package com.szholly.pro.watergas_server.ps.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.common.web.BaseController;
import com.szholly.pro.watergas_server.common.web.RequestUnit;
import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.ITable;
import com.szholly.data.general.ITableFactory;
import com.szholly.data.general.RowBase;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping("/DataValidate/*")
public class OperationDataValidateController extends BaseController{
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 获取站点数据有效性统计结果
	 * create by kbb 2015-11-12
	 */
	@RequestMapping(value = "/queryMonitorDataValidationStatisticsTotal")
	public void queryMonitorDataValidationStatisticsTotal(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();        
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		
		List<HashMap<String, String>> dataValidationList = getStationParamValidationList(resqMap);
		JSONArray jsonObj = JSONArray.fromObject(dataValidationList);
		outString(jsonObj.toString());
	}
	
	
	/**
	 * 获取参数的事件有效性统计结果列表
	 * create by kbb 2015-11-12
	 */
	@RequestMapping(value = "/queryMonitorDataEventValidationList")
	public void queryMonitorDataEventValidationList(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>(); 
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		
		List<HashMap<String,String>> eventValidationCollection = new ArrayList<HashMap<String, String>>();
		List<HashMap<String,String>> paramList = getStationParamList(resqMap);
		for (int i=0; i<paramList.size(); i++){	
			resqMap.put("PARAM_ID", paramList.get(i).get("PARAM_ID"));
			resqMap.put("PARAM_NAME", paramList.get(i).get("PARAM_NAME"));
			
			HashMap<String, String> device = getParamDeviceOnline(resqMap);
			if (device == null)
				continue;
			
			resqMap.put("DEVICE_ID", device.get("DEVICE_ID"));		
			List<HashMap<String, String>> eventValidationList = getParamEventValidationList(resqMap);
			eventValidationCollection.addAll(eventValidationList);
		}
		
		JSONArray jsonObj = JSONArray.fromObject(eventValidationCollection);
		outString(jsonObj.toString());
	}
	
	/**
	 * 获取参数的事件有效性统计结果列表
	 * create by kbb 2015-11-12
	 */
	@RequestMapping(value = "/queryOperationEventValidationList")
	public void queryOperationEventValidationList(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>(); 
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		
		List<HashMap<String,String>> eventValidationCollection = new ArrayList<HashMap<String, String>>();
		List<HashMap<String,String>> paramList = getStationParamList(resqMap);
		for (int i=0; i<paramList.size(); i++){	
			resqMap.put("PARAM_ID", paramList.get(i).get("PARAM_ID"));
			resqMap.put("PARAM_NAME", paramList.get(i).get("PARAM_NAME"));
			
			HashMap<String, String> device = getParamDeviceOnline(resqMap);
			if (device == null)
				continue;
						
			resqMap.put("DEVICE_ID", device.get("DEVICE_ID"));		
			List<HashMap<String, String>> eventValidationList = getParamEventValidationList(resqMap);
			eventValidationCollection.addAll(eventValidationList);
		}
		
//		eventValidationCollection.sort(new TaskValidationCompare());
		
		JSONArray jsonObj = JSONArray.fromObject(eventValidationCollection);
		outString(jsonObj.toString());
	}
	
	
	/**
	 * 获取任务有效性统计结果
	 * create by kbb 2015-11-12
	 */
	@RequestMapping(value = "/queryTaskValidationList")
	public void queryTaskValidationList(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>(); 
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		resqMap.put("PARAM_ID", RequestUnit.getString("PARAM_ID"));
		resqMap.put("JOB_ID", RequestUnit.getString("JOB_ID"));
		
		List<HashMap<String, String>> taskList = null;
		String strJOB_ID = resqMap.get("JOB_ID");
		switch(strJOB_ID){
	    	case "0f9faa25-89e4-4ad6-869f-aa1beb70f7bc": { taskList = getSampleComparisonEventTaskValidationList(resqMap); }	break;
	    	case "21c74765-685e-4a89-a625-0fa8f3668fc5": { taskList = getStandardVerificationEventTaskValidationList(resqMap); }	break;
	    	case "5385ab20-26ee-4fd0-a419-1cd9174a9921": { taskList = getStandardSubstanceEventTaskValidationList(resqMap); 	}	break;
	    	case "2bf6c8b1-12c3-496c-8e1b-96b52157e12c": { taskList = getExceedComparisonEventTaskValidationList(resqMap); } break;
	    	default:{};
		}
		
    	JSONArray jsonObj = JSONArray.fromObject(taskList);
		outString(jsonObj.toString());
	}
	
	// 4.3.1.1.获取站点数据有效性列表
	public List<HashMap<String, String>> getStationParamValidationList(HashMap<String, String> resqMap) throws Exception {
		
		List<HashMap<String, String>> paramValidationList = new ArrayList<HashMap<String, String>>();
		List<HashMap<String, String>> paramList = getStationParamList(resqMap);
		for(int i=0; i<paramList.size(); i++){
			resqMap.put("PARAM_ID", paramList.get(i).get("PARAM_ID"));
			resqMap.put("PARAM_NAME", paramList.get(i).get("PARAM_NAME"));
			HashMap<String, String> paramValidation = getParamValidation(resqMap);
			if (paramValidation == null)
				continue;
			
			paramValidationList.add(paramValidation);
		}
		return null;
	}	
	
	// 4.3.1.2.获取站点数据参数项列表
	/*public List<String> getStationParamList(HashMap<String, String> resqMap){
		return null;
	}*/
		
	// 4.3.1.3.获取单个数据有效性
	public HashMap<String, String> getParamValidation(HashMap<String, String> resqMap) throws Exception {
	
		boolean isParamValidation = true;
		HashMap<String, String> paramValidationMap = cloneHashMap(resqMap);
		
		List<HashMap<String, String>> eventValidationList = getParamEventValidationList(paramValidationMap);
		for (int i=0; i<eventValidationList.size(); i++){
			HashMap<String, String> eventValidation = eventValidationList.get(i);
			if (eventValidation == null)
				continue;
			
			if (eventValidation.get("JOB_VALIDATION").equals("0")){
				isParamValidation = false;
			}
		}
		
		paramValidationMap.put("PARAM_VALIDATION", isParamValidation ? "1" : "0");
		return paramValidationMap;
	}
	
	// 4.3.1.4.获取数据项事件有效性列表
	public List<HashMap<String,String>> getParamEventValidationList(HashMap<String, String> resqMap) throws Exception {
		
		String strJOB_ID = "";
		List<HashMap<String, String>> eventValidationList = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> eventMap = cloneHashMap(resqMap);
		List<HashMap<String, String>> eventList = getParamEventList(eventMap);
		HashMap<String,String> device = getParamDeviceOnline(eventMap);
		if (device != null){
			eventMap.put("DEVICE_ID", device.get("DEVICE_ID"));
		}
		
		for (int i=0; i<eventList.size(); i++){
			HashMap<String, String> event = eventList.get(i);
			
			eventMap.put("JOB_ID", event.get("JOB_ID"));
			eventMap.put("JOB_NAME", event.get("JOB_NAME"));
			eventMap.put("JOB_CYCLE", event.get("JOB_CYCLE"));
			eventMap.put("JOB_TOLERANCE", event.get("JOB_TOLERANCE"));
			eventMap.put("JOB_CYCLE_NAME", event.get("JOB_CYCLE_NAME"));
			eventMap.put("JOB_TOLERANC_NAME", event.get("JOB_TOLERANC_NAME"));
			
			HashMap<String, String> eventValidation = null;
        	strJOB_ID = event.get("JOB_ID"); // 此处JOB_ID进入不同的事件处理分支
        	switch(strJOB_ID){
	        	case "0f9faa25-89e4-4ad6-869f-aa1beb70f7bc": { eventValidation = getSampleComparisonEventValidation(eventMap); }	break;
	        	case "21c74765-685e-4a89-a625-0fa8f3668fc5": { eventValidation = getStandardVerificationEventValidation(eventMap);  } break;
	        	case "5385ab20-26ee-4fd0-a419-1cd9174a9921": { eventValidation = getStandardSubstanceEventValidation(eventMap);  } break;
	        	case "2bf6c8b1-12c3-496c-8e1b-96b52157e12c": { eventValidation = getExceedComparisonEventValidation(eventMap); } break;
	        	default:{};
        	}
        	
        	if (eventValidation == null)
        		continue;
        	
        	eventValidationList.add(eventValidation);
		}
        
		return eventValidationList;
	}
	
	// 4.3.1.5.获取数据项关联事件列表
	public List<HashMap<String,String>> getParamEventList(HashMap<String, String> resqMap){
		
		String strPARAM_ID = resqMap.get("PARAM_ID");
		String strJOB_ID = resqMap.get("JOB_ID");
	
		String strSQL = " select t1.*,  "
				+ " d1.S_DOMAINCAPTION as JOB_TOLERANCE_NAME, "
				+ " d2.S_DOMAINCAPTION as JOB_CYCLE_NAME "
				+ " from OC_PARM_EVENT t1"
				+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'OPERATION_TOLERANCE_TIME' AND d1.S_DOMAINCODE = t1.DEFAULT_TOLERANCE ) "
				+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'OPERATION_CYCLE_TIME' AND d2.S_DOMAINCODE = t1.DEFAULT_CYCLE ) "
				+ " where 1=1 ";
				
		if (strPARAM_ID !=null && strPARAM_ID.length()>0){
			strSQL = strSQL + " AND ( t1.PARM_ID = '"+strPARAM_ID+"') ";
		}
		
		if (strJOB_ID !=null && strJOB_ID.length()>0){
			strSQL = strSQL + " AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);		// 此处关联总字典表，getList函数需重载
		if (rcdList.size()<1)
			return null;
		
		List<HashMap<String, String>> eventMap = new ArrayList<HashMap<String, String>>();
		for (int i=0; i<rcdList.size(); i++){
			HashMap<String, String> event = new HashMap<String, String>();
			event.put("JOB_NAME", rcdList.get(i).getSafeString("NAME").toString()); 
			event.put("JOB_ID", rcdList.get(i).getSafeString("JOB_ID").toString()); 
			event.put("JOB_CYCLE", rcdList.get(i).getSafeString("DEFAULT_CYCLE").toString());
			event.put("JOB_TOLERANCE", rcdList.get(i).getSafeString("DEFAULT_TOLERANCE").toString());	
			event.put("JOB_CYCLE_NAME", rcdList.get(i).getSafeString("JOB_CYCLE_NAME").toString());
			event.put("JOB_TOLERANCE_NAME", rcdList.get(i).getSafeString("JOB_TOLERANCE_NAME").toString());
			eventMap.add(event);
		}
		
		if (eventMap.size()<1)
			return null;
		
		return eventMap;
	}
	
	// 4.3.1.6.获取数据项关联唯一在线设备
	public HashMap<String, String> getParamDeviceOnline(HashMap<String, String> resqMap){
		
		HashMap<String, String> device = null;
		List<HashMap<String, String>> deviceList = getParamDeviceList(resqMap);
		if (deviceList == null)
			return null;

		for (int i=0; i<deviceList.size(); i++){
			device = deviceList.get(i);
			if (device.get("DEVICE_STATUS").equals("1")){
				break;
			}
		}
		
		return device;
	}
	
	// 4.3.1.7.获取数据项关联设备列表
	public List<HashMap<String, String>> getParamDeviceList(HashMap<String, String> resqMap){
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strPARAM_ID = resqMap.get("PARAM_ID");
		
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		String strSQL = " select t1.*  "
				+ " from BC_SITE_DEVICE_RPT t1 "
				+ " left join BC_SITE_INFO t2 on ( t1.MONITOR_POINT = t2.EXP_NO ) "
				+ " left join BC_SITE_POLL  t3 on ( t1.MONITOR_POLLUTANTS = t3.NAME  AND t1.MONITOR_POINT = t3.site_id ) "
				+ " where 1=1 ";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t1.WSCLC_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.WSCLC_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.MONITOR_POINT LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.MONITOR_POINT LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t2.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t2.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strPARAM_ID!=null && strPARAM_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t3.name = '"+strPARAM_ID+"') ";
		}
		
		List<GlobalParameter> parameter = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, parameter);
		if (rcdList.size()<1)
			return null;
		
		List<HashMap<String, String>> deviceList = new ArrayList<HashMap<String, String>>();
		for (int i=0; i<rcdList.size(); i++){
			HashMap<String, String> device = new HashMap<String, String>();
			device.put("PARAM_ID", strPARAM_ID);
			device.put("DEVICE_ID", rcdList.get(i).getSafeString("DEVICE_NUM").toString());
			device.put("DEVICE_NAME", rcdList.get(i).getSafeString("NAME").toString());
			device.put("DEVICE_STATUS", rcdList.get(i).getSafeString("STATUS").toString());
			deviceList.add(device);
		}
		if (deviceList.size()<1)
			return null;
		
		return deviceList;
	}
	
	/**
	 * 获取水样比对事件有效性
	 * create by kbb 2015-11-12
	 */
	// 4.3.2.1.获取水样比对事件有效性
	public HashMap<String,String> getSampleComparisonEventValidation(HashMap<String, String> resqMap) throws Exception {
		
		boolean isEvnetValidation = true;	
		int nAccuracy = 0;
		int nTimely = 0;
		
		HashMap<String, String> eventValidationMap = cloneHashMap(resqMap);
		
		List<HashMap<String, String>> taskValidationList = getSampleComparisonEventTaskValidationList(eventValidationMap); 
		if (taskValidationList == null)
			return null;
		
		for (int i=0; i<taskValidationList.size(); i++){
			HashMap<String, String> taskValidation = taskValidationList.get(i);
			if (taskValidation == null)
				continue;
			
			if (taskValidation.get("MEASURE_ACCURACY").equals("1")) // 偏差合格次数
				nAccuracy++;
			
			if (taskValidation.get("MEASURE_TIMELY").equals("1"))	// 及时完成次数
				nTimely++;
			
			if (taskValidation.get("MEASURE_ACCURACY").equals("0"))
				isEvnetValidation = false;
			
			if (taskValidation.get("MEASURE_TIMELY").equals("0"))
				isEvnetValidation = false;
		}
		
		List<RowBase> taskRcdList = getSampleComparisonEventTaskRcdList(eventValidationMap);
		if (taskRcdList == null)
			return null;
		
		if (taskValidationList.size() < taskRcdList.size()){
			isEvnetValidation = false;
		}
		
		eventValidationMap.put("JOB_VALIDATION", isEvnetValidation ? "有效": "无效");
		eventValidationMap.put("MEASURE_STD_NUM", Integer.toString(taskRcdList.size()));
		eventValidationMap.put("MEASURE_ACT_NUM", Integer.toString(taskValidationList.size()));
		eventValidationMap.put("MEASURE_TIMELY_NUM", Integer.toString(nTimely));
		eventValidationMap.put("MEASURE_ACCURACY_NUM", Integer.toString(nAccuracy));
		
		return eventValidationMap;
	}
	
	// 4.3.2.2.获取水样比对任务有效性列表
	public List<HashMap<String, String>> getSampleComparisonEventTaskValidationList(HashMap<String, String> resqMap) throws Exception {
		
		List<HashMap<String, String>> taskList = getSampleComparisonAggregateTaskRstList(resqMap);
		
		calSampleComparisonAggregateTaskRstList(resqMap, taskList);
		
		return taskList;
	}
	
	// 4.3.2.3.获取水样比对聚合任务列表
	public List<HashMap<String, String>> getSampleComparisonAggregateTaskRstList(HashMap<String, String> resqMap) throws Exception {
		
		boolean isExist = false;
		double dMin = 0.0;
		double dMax = 0.0;
		double dDeviation = 0.0;
		
		List<HashMap<String, String>> taskRstList = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> tempTask = null;
		
		List<RowBase> dataRcdList = getSampleComparisonEventDataRcdList(resqMap);
		if (dataRcdList == null)
			return null;
		
		for (int i=0; i<dataRcdList.size(); i++){
			isExist = false;	
		   
			// 合并相同日期数据记录为任务记录
			for (int j=0; j<taskRstList.size(); j++){ 
				
				tempTask = taskRstList.get(j);
				
				if (tempTask.get("TASK_ID").equals(dataRcdList.get(i).getSafeString("TASK_ID"))){
					
					// 获取合格偏差最大最小值
					dDeviation = Double.parseDouble(dataRcdList.get(i).getSafeString("MEASURE_DEVIATION"));
					dMin = Double.parseDouble(tempTask.get("MEASURE_MIN"));
					dMax = Double.parseDouble(tempTask.get("MEASURE_MAX"));
					
					if (dDeviation<dMin)
						dMin = dDeviation;
						
					if (dDeviation>dMax)
						dMax = dDeviation;
						
					tempTask.put("MEASURE_MIN", Double.toString(dMin));
					tempTask.put("MEASURE_MAX", Double.toString(dMax));
					
					// 获取测量次数和合格次数
					boolean  isAccuracy = true;
					int nMEASURE_NUM = Integer.parseInt(tempTask.get("MEASURE_NUM"));
					int nMEASURE_ACCURACY_NUM = Integer.parseInt(tempTask.get("MEASURE_ACCURACY_NUM"));
					String strMEASURE_CONCLUSION = dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION").toString();
					if (strMEASURE_CONCLUSION.equals("1")){
						nMEASURE_ACCURACY_NUM++;
					}
					nMEASURE_NUM++;	
					
					if (nMEASURE_NUM < 3)
						isAccuracy = false;
					
					if ((nMEASURE_NUM-nMEASURE_ACCURACY_NUM) > 1)
						isAccuracy = false;
													
					tempTask.put("MEASURE_NUM", Integer.toString(nMEASURE_NUM));
					tempTask.put("MEASURE_ACCURACY_NUM", Integer.toString(nMEASURE_ACCURACY_NUM));
					tempTask.put("MEASURE_ACCURACY", (isAccuracy ? "1" : "0") );
					tempTask.put("MEASURE_CONCLUSION_NAME", (isAccuracy ? "合格" : "不合格"));
					
					taskRstList.set(j, tempTask); 
					
					isExist = true;
				}
			}
			
			// 如果存在同日期记录则不添加
			if (!isExist) {
				
				HashMap<String, String> task = new HashMap<String, String>();
				
				task.put("WWTP_ID", dataRcdList.get(i).getSafeString("WWTP_ID"));
				task.put("STATION_ID", dataRcdList.get(i).getSafeString("STATION_ID"));
				task.put("MEASURE_ITEM", dataRcdList.get(i).getSafeString("MEASURE_ITEM"));
				task.put("MEASURE_PERSON", dataRcdList.get(i).getSafeString("MEASURE_PERSON"));
				task.put("MEASURE_START_TIME", dataRcdList.get(i).getSafeString("MEASURE_START_TIME"));
				task.put("MEASURE_ACCURACY", dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION"));
				task.put("MEASURE_NUM", "1");
				task.put("MEASURE_ACCURACY_NUM", dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION"));
				task.put("TASK_ID", dataRcdList.get(i).getSafeString("TASK_ID"));
				task.put("TASK_STATUS", dataRcdList.get(i).getSafeString("TASK_STATUS"));
				task.put("TASK_CYCLE", dataRcdList.get(i).getSafeString("TASK_CYCLE"));
				task.put("TASK_TOLERANCE", dataRcdList.get(i).getSafeString("TASK_TOLERANCE"));
				task.put("TASK_START_TIME", dataRcdList.get(i).getSafeString("TASK_START_TIME"));
				task.put("TASK_END_TIME", dataRcdList.get(i).getSafeString("TASK_END_TIME"));
				task.put("TASK_FINISH_TIME", dataRcdList.get(i).getSafeString("TASK_FINISH_TIME"));
				task.put("WWTP_NAME", dataRcdList.get(i).getSafeString("WWTP_NAME"));
				task.put("STATION_NAME", dataRcdList.get(i).getSafeString("STATION_NAME"));
				task.put("FLOW_TYPE_NAME", dataRcdList.get(i).getSafeString("FLOW_TYPE_NAME"));
				task.put("MEASURE_PERSON_NAME", dataRcdList.get(i).getSafeString("MEASURE_PERSON_NAME"));
				task.put("MEASURE_CONCLUSION_NAME", dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION_NAME"));
				task.put("MEASURE_ITEM_NAME", dataRcdList.get(i).getSafeString("MEASURE_ITEM_NAME"));
				
				task.put("MEASURE_DATE", dataRcdList.get(i).getSafeString("MEASURE_START_TIME"));
				task.put("MEASURE_MIN", dataRcdList.get(i).getSafeString("MEASURE_DEVIATION"));
				task.put("MEASURE_MAX", dataRcdList.get(i).getSafeString("MEASURE_DEVIATION"));
				
				taskRstList.add(task);
			}
		}
		
		return taskRstList;
	}
	
	// 4.3.2.4.计算水样比对聚合任务结果列表
	public void calSampleComparisonAggregateTaskRstList(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception{
		
		calSampleComparisonTaskListBeforeTime(resqMap, taskList);
		
		calSampleComparisonTaskListTimelyTime(resqMap, taskList);	
	}
	
	// 4.3.2.5.查询水样比对事件数据记录列表
	public List<RowBase> getSampleComparisonEventDataRcdList(HashMap<String, String> resqMap) throws Exception {

		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrMEASURE_ITEM = strMEASURE_ITEM.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";		
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";			
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); 	// 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = " select t1.*, "
						+ " t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, t2.JOB_ID, "
						+ " t3.name as WWTP_NAME,"
						+ " t4.WWTP_ID, t4.name as STATION_NAME, t4.flow_type,  "
						+ " t5.name DEVICE_ALIAS_NAME, "
						+ " t6.c_userealname as MEASURE_PERSON_NAME, "
						+ " d1.S_DOMAINCAPTION as MEASURE_ITEM_NAME, "
						+ " d2.S_DOMAINCAPTION as FLOW_TYPE_NAME, "
						+ " d3.S_DOMAINCAPTION as MEASURE_CONCLUSION_NAME "
						+ " from OP_SAMPLE_COMP t1 "
						+ " left join OPERATION_TASK t2 on t1.TASK_ID = t2.TASK_CODE "				
						+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t3 on t2.WWTP_ID = t3.EXP_NO "
						+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NUMBER = t5.device_num "
						+ " left join safe_user t6 on t1.MEASURE_PERSON = t6.s_userid "
						+ " left join OC_TASK_CONFIG t7 on ( t7.JOB_ID = t2.JOB_ID AND t7.PARM_ID = t1.MEASURE_ITEM ) "
						+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'MONITOR_PARAM' AND d1.S_DOMAINCODE = t1.MEASURE_ITEM ) "
						+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
						+ " left join DATA_DEFULATDOMAIN d3 on ( d3.S_DOMAINNAME = 'OPERATION_COMPARISON_CONCLUSION' AND d3.S_DOMAINCODE = t1.MEASURE_CONCLUSION ) "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t4.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t4.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_ITEM.length()>0 && arrMEASURE_ITEM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrMEASURE_ITEM.length; i++){
				if(i<arrMEASURE_ITEM.length-1)
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' OR ";
				else
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}		
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_END_DATE!=null && strMEASURE_END_DATE.length()>0)
		{
			strSQL = strSQL + "AND t2.START_TIME <= to_date('"+strMEASURE_END_DATE+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME ";
			
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.2.6.查询事件任务记录列表
	public List<RowBase> getSampleComparisonEventTaskRcdList(HashMap<String, String> resqMap) throws Exception {
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select t1.*  from OP_TASK  t1 "										
						+ " left join BC_SITE_INFO t3 on t1.STATION_ID = t3.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t2 on t3.WWTP_ID = t2.EXP_NO "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME <= to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.2.7.计算任务上次任务测量日期
	public void calSampleComparisonTaskListBeforeTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		String strLastTime = getSampleComparisonLastDataRcdTime(resqMap);
		
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
				
			// 获取上次任务测量日期
			if (i==0){
				if (strLastTime == null || strLastTime.length()<1){
					String strMeasureDate = task.get("MEASURE_DATE");
					strLastTime = strMeasureDate;
				}
					
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			else{
				HashMap<String, String> taskBefore = taskList.get(i-1);
				strLastTime = taskBefore.get("MEASURE_DATE");
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			
			taskList.set(i, task);
		}
	}
	
	// 4.3.2.8.计算任务应该完成日期
	public void calSampleComparisonTaskListTimelyTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		// 获取事件周期和容限
		getEventCycleAndTolerance(resqMap);
		
		// 解析容限时间，容限时间只考虑“天”为单位
		String strJOB_TOLERANCE = resqMap.get("JOB_TOLERANCE");
		String strTOLERANCE = strJOB_TOLERANCE.replace("D", ""); 	
		int nTOLERANCE = Integer.parseInt(strTOLERANCE);
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();	
		
		// 遍历计算间隔日期
        for (int i=0; i<taskList.size();i++){
        	HashMap<String, String> task = taskList.get(i);
        	String strLastTime = task.get("MEASURE_BEFORE_DATE");
        	String strEndTime= task.get("TASK_END_TIME");
        	String strFinishTime = task.get("TASK_FINISH_TIME");

        	Date dateLast = sdf.parse(strLastTime);
        	Date dateEnd = sdf.parse(strEndTime);
        	Date dateFinish = sdf.parse(strFinishTime);
        	
        	int nIntervalDays = (int)((dateFinish.getTime()-dateLast.getTime())/(1000*60*60*24));
			task.put("MEASURE_DATE_INTERVAL", Integer.toString(nIntervalDays));
        	
        	dateLast = cal.getTime();
        	nIntervalDays = (int)((dateFinish.getTime()-dateEnd.getTime())/(1000*60*60*24));       	
			task.put("MEASURE_TIMELY", nIntervalDays <= nTOLERANCE ? "1" : "0");
			task.put("MEASURE_TIMELY_NAME", nIntervalDays <= nTOLERANCE ? "及时" : "不及时");		
        }
	}
	
	// 4.3.2.9.获取上次最近的数据记录日期
	public String getSampleComparisonLastDataRcdTime(HashMap<String, String> resqMap) throws Exception {
		
		List<RowBase> rcdList = getSampleComparisonBeforeDataRcdList(resqMap);
		if (rcdList==null || rcdList.size()<1)
			return "";
		
		String strLastTime = rcdList.get(0).getSafeString("MEASURE_START_TIME");	
		return strLastTime;
	}
	
	// 4.3.2.10.获取指定日期之前的测量数据记录
	public List<RowBase> getSampleComparisonBeforeDataRcdList(HashMap<String, String> resqMap) throws Exception {

		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrMEASURE_ITEM = strMEASURE_ITEM.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select * from ( "
						+ " select t1.*, t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, t2.JOB_ID, "
						+ " t3.name as WWTP_NAME,t4.name as STATION_NAME, t4.flow_type, t5.name DEVICE_ALIAS_NAME, t6.c_userealname as MEASURE_PERSON_NAME, "
						+ " t7.TASK_CYCLE, t7.TASK_TOLERANCE, "
						+ " d1.S_DOMAINCAPTION as MEASURE_ITEM_NAME, d2.S_DOMAINCAPTION as FLOW_TYPE_NAME, d3.S_DOMAINCAPTION as MEASURE_CONCLUSION_NAME  "
						+ " from OP_SAMPLE_COMP t1 "
						+ " left join OPERATION_TASK t2 on t1.TASK_ID = t2.TASK_CODE "
						+ " left join BC_ENTERPRISE_ATTR t3 on t2.WWTP_ID = t3.EXP_NO "
						+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
						+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NUMBER = t5.device_num "
						+ " left join safe_user t6 on t1.MEASURE_PERSON = t6.s_userid "
						+ " left join OC_TASK_CONFIG t7 on t7.JOB_ID = t2.JOB_ID "
						+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'MONITOR_PARAM' AND d1.S_DOMAINCODE = t1.MEASURE_ITEM ) "
						+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
						+ " left join DATA_DEFULATDOMAIN d3 on ( d3.S_DOMAINNAME = 'OPERATION_COMPARISON_CONCLUSION' AND d3.S_DOMAINCODE = t1.MEASURE_CONCLUSION ) "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t2.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_ITEM.length()>0 && arrMEASURE_ITEM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrMEASURE_ITEM.length; i++){
				if(i<arrMEASURE_ITEM.length-1)
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' OR ";
				else
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}		
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.MEASURE_START_TIME < to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		strSQL = strSQL + " order by t1.MEASURE_START_TIME desc "
						+ " )  where rownum = 1 ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	
	/**
	 * 获取标样核查事件有效性
	 * create by kbb 2015-11-12
	 */
	// 4.3.3.1.获取标样核查事件有效性
	public HashMap<String,String> getStandardVerificationEventValidation(HashMap<String, String> resqMap) throws Exception{
		boolean isEvnetValidation = true;	
		int nAccuracy = 0;
		int nTimely = 0;
		
		HashMap<String, String> eventValidationMap = cloneHashMap(resqMap);
		
		List<HashMap<String, String>> taskValidationList = getStandardVerificationEventTaskValidationList(eventValidationMap); 
		if (taskValidationList == null)
			return null;
		
		for (int i=0; i<taskValidationList.size(); i++){
			HashMap<String, String> taskValidation = taskValidationList.get(i);
			if (taskValidation == null)
				continue;
			
			if (taskValidation.get("MEASURE_ACCURACY").equals("1")) // 偏差合格次数
				nAccuracy++;
			
			if (taskValidation.get("MEASURE_TIMELY").equals("1"))	// 及时完成次数
				nTimely++;
			
			if (taskValidation.get("MEASURE_ACCURACY").equals("0"))
				isEvnetValidation = false;
			
			if (taskValidation.get("MEASURE_TIMELY").equals("0"))
				isEvnetValidation = false;
		}
		
		List<RowBase> taskRcdList = getStandardVerificationEventTaskRcdList(eventValidationMap);
		if (taskRcdList == null)
			return null;
		
		if (taskValidationList.size() < taskRcdList.size()){
			isEvnetValidation = false;
		}
		
		eventValidationMap.put("JOB_VALIDATION", isEvnetValidation ? "有效": "无效");
		eventValidationMap.put("MEASURE_STD_NUM", Integer.toString(taskRcdList.size()));
		eventValidationMap.put("MEASURE_ACT_NUM", Integer.toString(taskValidationList.size()));
		eventValidationMap.put("MEASURE_TIMELY_NUM", Integer.toString(nTimely));
		eventValidationMap.put("MEASURE_ACCURACY_NUM", Integer.toString(nAccuracy));
		
		return eventValidationMap;
	}
	
	// 4.3.3.2.获取标样核查事件任务有效性列表
	public List<HashMap<String, String>> getStandardVerificationEventTaskValidationList(HashMap<String, String> resqMap) throws Exception{
		
		List<HashMap<String, String>> taskList = getStandardVerificationAggregateTaskRstList(resqMap);
		
		calStandardVerificationAggregateTaskRstList(resqMap, taskList);
		
		return taskList;
	}
	
	// 4.3.3.3.获取标样核查数据聚合任务列表
	public List<HashMap<String, String>> getStandardVerificationAggregateTaskRstList(HashMap<String, String> resqMap) throws Exception{
		boolean isExist = false;
		double dMin = 0.0;
		double dMax = 0.0;
		double dDeviation = 0.0;
		
		List<HashMap<String, String>> taskRstList = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> tempTask = null;
		
		List<RowBase> dataRcdList = getStandardVerificationEventDataRcdList(resqMap);
		if (dataRcdList == null)
			return null;
		
		for (int i=0; i<dataRcdList.size(); i++){
			isExist = false;	
		   
			// 合并相同日期数据记录为任务记录
			for (int j=0; j<taskRstList.size(); j++){ 
				
				tempTask = taskRstList.get(j);
				
				if (tempTask.get("TASK_CODE").equals(dataRcdList.get(i).getSafeString("TASK_CODE").toString())){
					
					// 获取偏差最大最小值
					dDeviation = Double.parseDouble(dataRcdList.get(i).getSafeString("OPPOSITE_ERROR").toString());
					dMin = Double.parseDouble(tempTask.get("MEASURE_MIN"));
					dMax = Double.parseDouble(tempTask.get("MEASURE_MAX"));
					
					if (dDeviation<dMin)
						dMin = dDeviation;
						
					if (dDeviation>dMax)
						dMax = dDeviation;
						
					tempTask.put("MEASURE_MIN", Double.toString(dMin));
					tempTask.put("MEASURE_MAX", Double.toString(dMax));
					
					// 获取测量次数和合格次数
					boolean  isAccuracy = true;
					int nMEASURE_NUM = Integer.parseInt(tempTask.get("MEASURE_NUM"));
					int nMEASURE_ACCURACY_NUM = Integer.parseInt(tempTask.get("MEASURE_ACCURACY_NUM"));
					String strMEASURE_CONCLUSION = dataRcdList.get(i).getSafeString("CONCLUSION").toString();
					if (strMEASURE_CONCLUSION.equals("1")){
						nMEASURE_ACCURACY_NUM++;
					}
					nMEASURE_NUM++;	
					
					/*
					if (nMEASURE_NUM < 3)
						isAccuracy = false;
						*/
					
					if ((nMEASURE_NUM-nMEASURE_ACCURACY_NUM) > 1)
						isAccuracy = false;
													
					tempTask.put("MEASURE_NUM", Integer.toString(nMEASURE_NUM));
					tempTask.put("MEASURE_ACCURACY_NUM", Integer.toString(nMEASURE_ACCURACY_NUM));
					tempTask.put("MEASURE_ACCURACY", (isAccuracy ? "1" : "0") );
					tempTask.put("MEASURE_CONCLUSION_NAME", (isAccuracy ? "合格" : "不合格") );
							
					taskRstList.set(j, tempTask); 
					
					isExist = true;
				}
			}
			
			// 如果存在同日期记录则不添加
			if (!isExist) {
				
				HashMap<String, String> task = new HashMap<String, String>();
				
				task.put("WWTP_ID", dataRcdList.get(i).getSafeString("WWTP_ID"));
				task.put("STATION_ID", dataRcdList.get(i).getSafeString("STATION_ID"));
				task.put("MEASURE_ITEM", dataRcdList.get(i).getSafeString("TEST_PROJECT"));
				task.put("MEASURE_PERSON", dataRcdList.get(i).getSafeString("SUER_ID"));
				task.put("MEASURE_START_TIME", dataRcdList.get(i).getSafeString("START_TIME")); //
				task.put("MEASURE_ACCURACY", dataRcdList.get(i).getSafeString("CONCLUSION"));
				task.put("MEASURE_NUM", "1");
				task.put("MEASURE_ACCURACY_NUM", dataRcdList.get(i).getSafeString("CONCLUSION"));
				task.put("TASK_CODE", dataRcdList.get(i).getSafeString("TASK_CODE"));
				task.put("TASK_CYCLE", dataRcdList.get(i).getSafeString("TASK_CYCLE"));
				task.put("TASK_TOLERANCE", dataRcdList.get(i).getSafeString("TASK_TOLERANCE"));
				task.put("TASK_START_TIME", dataRcdList.get(i).getSafeString("TASK_START_TIME"));
				task.put("TASK_END_TIME", dataRcdList.get(i).getSafeString("TASK_END_TIME"));
				task.put("TASK_FINISH_TIME", dataRcdList.get(i).getSafeString("TASK_FINISH_TIME"));
				task.put("WWTP_NAME", dataRcdList.get(i).getSafeString("WWTP_NAME"));
				task.put("STATION_NAME", dataRcdList.get(i).getSafeString("STATION_NAME"));
				task.put("FLOW_TYPE_NAME", dataRcdList.get(i).getSafeString("FLOW_TYPE_NAME"));
				task.put("MEASURE_PERSON_NAME", dataRcdList.get(i).getSafeString("MEASURE_PERSON_NAME"));
				task.put("MEASURE_CONCLUSION_NAME", dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION_NAME"));
				task.put("MEASURE_ITEM_NAME", dataRcdList.get(i).getSafeString("MEASURE_ITEM_NAME"));
				
				task.put("MEASURE_DATE", dataRcdList.get(i).getSafeString("START_TIME"));		
				task.put("MEASURE_MIN", dataRcdList.get(i).getSafeString("OPPOSITE_ERROR"));
				task.put("MEASURE_MAX", dataRcdList.get(i).getSafeString("OPPOSITE_ERROR"));
				
				taskRstList.add(task);
			}
		}
			
		return taskRstList;
	}
	
	// 4.3.3.4.计算标样核查数据聚合结果列表
	public void calStandardVerificationAggregateTaskRstList(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception{
		
		calStandardVerificationTaskListBeforeTime(resqMap, taskList);	
		calStandardVerificationTaskListTimelyTime(resqMap, taskList);	
	}
	
	// 4.3.3.5.查询标样核查事件数据记录列表
	public List<RowBase> getStandardVerificationEventDataRcdList(HashMap<String, String> resqMap) throws Exception {
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrMEASURE_ITEM = strMEASURE_ITEM.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";		
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";			
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); 	// 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
        String strSQL = " select t1.*, "
        		+ " t2.TASK_STATUS, t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, "
				+ " t3.name as WWTP_NAME, "
				+ " t4.name as STATION_NAME, t4.flow_type, "
				+ " t5.name DEVICE_ALIAS_NAME, "
				+ " t6.c_userealname as MEASURE_PERSON_NAME, "
				+ " t7.DEFAULT_CYCLE as JOB_CYCLE, t7.DEFAULT_TOLERANCE as JOB_TOLERANCE,"
				+ " d1.S_DOMAINCAPTION as MEASURE_ITEM_NAME, "
				+ " d2.S_DOMAINCAPTION as FLOW_TYPE_NAME, "
				+ " d3.S_DOMAINCAPTION as MEASURE_CONCLUSION_NAME "
				+ " from OP_STAND_VERI t1 "
				+ " left join OPERATION_TASK t2 on t1.TASK_CODE = t2.TASK_CODE "	
				+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
				+ " left join BC_ENTERPRISE_ATTR t3 on t4.WWTP_ID = t3.EXP_NO "
				+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NUMBER = t5.device_num "
				+ " left join safe_user t6 on t1.SUER_ID = t6.s_userid "
				+ " left join OC_PARM_EVENT t7 on ( t7.JOB_ID = t2.JOB_ID AND t7.PARM_ID = t1.TEST_PROJECT ) "
				+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'MONITOR_PARAM' AND d1.S_DOMAINCODE = t1.TEST_PROJECT ) "
				+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
				+ " left join DATA_DEFULATDOMAIN d3 on ( d3.S_DOMAINNAME = 'OPERATION_COMPARISON_CONCLUSION' AND d3.S_DOMAINCODE = t1.CONCLUSION ) "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t4.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t4.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_ITEM.length()>0 && arrMEASURE_ITEM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrMEASURE_ITEM.length; i++){
				if(i<arrMEASURE_ITEM.length-1)
					strSQL = strSQL + "t1.TEST_PROJECT = '"+arrMEASURE_ITEM[i]+"' OR ";
				else
					strSQL = strSQL + "t1.TEST_PROJECT = '"+arrMEASURE_ITEM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
			
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME >= to_date('"+strMEASURE_START_DATE +" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_END_DATE!=null && strMEASURE_END_DATE.length()>0)
		{
			strSQL = strSQL + "AND t1.END_TIME <= to_date('"+strMEASURE_END_DATE +" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
			
		strSQL = strSQL + " order by t1.START_TIME ASC ";
			
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.2.6.查询事件任务记录列表
	public List<RowBase> getStandardVerificationEventTaskRcdList(HashMap<String, String> resqMap) throws Exception {
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select t1.*  from OP_TASK  t1 "										
						+ " left join BC_SITE_INFO t3 on t1.STATION_ID = t3.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t2 on t3.WWTP_ID = t2.EXP_NO "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME <= to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.3.7.计算任务上次任务测量日期
	public void calStandardVerificationTaskListBeforeTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		String strLastTime = getStandardVerificationLastDataRcdTime(resqMap);
		
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
				
			// 获取上次任务测量日期
			if (i==0){
				if (strLastTime == null || strLastTime.length()<1){
					String strMeasureDate = task.get("MEASURE_DATE");
					strLastTime = strMeasureDate;
				}
					
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			else{
				HashMap<String, String> taskBefore = taskList.get(i-1);
				strLastTime = taskBefore.get("MEASURE_DATE");
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			
			taskList.set(i, task);
		}
	}
	
	// 4.3.3.8.计算任务应该完成日期
	public void calStandardVerificationTaskListTimelyTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		// 获取事件周期和容限
		getEventCycleAndTolerance(resqMap);
		
		// 解析容限时间，容限时间只考虑“天”为单位
		String strJOB_TOLERANCE = resqMap.get("JOB_TOLERANCE");
		String strTOLERANCE = strJOB_TOLERANCE.replace("D", ""); 	
		int nTOLERANCE = Integer.parseInt(strTOLERANCE);
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();	
		
		// 遍历计算间隔日期
        for (int i=0; i<taskList.size();i++){
        	HashMap<String, String> task = taskList.get(i);
        	String strLastTime = task.get("MEASURE_BEFORE_DATE");
        	String strEndTime= task.get("TASK_END_TIME");
        	String strFinishTime = task.get("TASK_FINISH_TIME");

        	Date dateLast = sdf.parse(strLastTime);
        	Date dateEnd = sdf.parse(strEndTime);
        	Date dateFinish = sdf.parse(strFinishTime);
        	
        	int nIntervalDays = (int)((dateFinish.getTime()-dateLast.getTime())/(1000*60*60*24));
			task.put("MEASURE_DATE_INTERVAL", Integer.toString(nIntervalDays));
        	
        	dateLast = cal.getTime();
        	nIntervalDays = (int)((dateFinish.getTime()-dateEnd.getTime())/(1000*60*60*24));       	
			task.put("MEASURE_TIMELY", nIntervalDays <= nTOLERANCE ? "1" : "0");
			task.put("MEASURE_TIMELY_NAME", nIntervalDays <= nTOLERANCE ? "及时" : "不及时");		
        }
	}
	
	// 4.3.3.9.获取上次最近的数据记录日期
	public String getStandardVerificationLastDataRcdTime(HashMap<String, String> resqMap) throws Exception {
		
		List<RowBase> rcdList = getStandardVerificationBeforeDataRcdList(resqMap);
		if (rcdList == null || rcdList.size()<1)
			return "";
		
		String strLastTime = rcdList.get(0).getSafeString("TASK_FINISH_TIME");	
		return strLastTime;
	}
	
	// 4.3.3.10.获取指定日期之前的测量数据记录
	public List<RowBase> getStandardVerificationBeforeDataRcdList(HashMap<String, String> resqMap) throws Exception {

		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrMEASURE_ITEM = strMEASURE_ITEM.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";		
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";			
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); 	// 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
        String strSQL = " select * from ( "
        		+ " select t1.*, "
        		+ " t2.TASK_STATUS, t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, "
				+ " t3.name as WWTP_NAME, "
				+ " t4.name as STATION_NAME, t4.flow_type, "
				+ " t5.name DEVICE_ALIAS_NAME, "
				+ " t6.c_userealname as MEASURE_PERSON_NAME, "
				+ " t7.DEFAULT_CYCLE as JOB_CYCLE, t7.DEFAULT_TOLERANCE as JOB_TOLERANCE,"
				+ " d1.S_DOMAINCAPTION as MEASURE_ITEM_NAME, "
				+ " d2.S_DOMAINCAPTION as FLOW_TYPE_NAME, "
				+ " d3.S_DOMAINCAPTION as MEASURE_CONCLUSION_NAME "
				+ " from OP_STAND_VERI t1 "
				+ " left join OPERATION_TASK t2 on t1.TASK_CODE = t2.TASK_CODE "	
				+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
				+ " left join BC_ENTERPRISE_ATTR t3 on t4.WWTP_ID = t3.EXP_NO "
				+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NUMBER = t5.device_num "
				+ " left join safe_user t6 on t1.SUER_ID = t6.s_userid "
				+ " left join OC_PARM_EVENT t7 on ( t7.JOB_ID = t2.JOB_ID AND t7.PARM_ID = t1.TEST_PROJECT ) "
				+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'MONITOR_PARAM' AND d1.S_DOMAINCODE = t1.TEST_PROJECT ) "
				+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
				+ " left join DATA_DEFULATDOMAIN d3 on ( d3.S_DOMAINNAME = 'OPERATION_COMPARISON_CONCLUSION' AND d3.S_DOMAINCODE = t1.CONCLUSION ) "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t4.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t4.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_ITEM.length()>0 && arrMEASURE_ITEM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrMEASURE_ITEM.length; i++){
				if(i<arrMEASURE_ITEM.length-1)
					strSQL = strSQL + "t1.TEST_PROJECT = '"+arrMEASURE_ITEM[i]+"' OR ";
				else
					strSQL = strSQL + "t1.TEST_PROJECT = '"+arrMEASURE_ITEM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
			
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME < to_date('"+strMEASURE_START_DATE +" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME desc "
						+ " )  where rownum = 1 ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}

	
	/**
	 * 获取标准物质更换事件有效性
	 * create by kbb 2015-11-12
	 */
	
	// 4.3.4.1.获取标准物质更换事件有效性
	public HashMap<String,String> getStandardSubstanceEventValidation(HashMap<String, String> resqMap) throws Exception{
		boolean isEvnetValidation = true;	
		int nTimely = 0;
		
		HashMap<String, String> eventValidationMap = cloneHashMap(resqMap);
		
		List<HashMap<String, String>> taskValidationList = getStandardSubstanceEventTaskValidationList(eventValidationMap); 
		if (taskValidationList == null)
			return null;
		
		for (int i=0; i<taskValidationList.size(); i++){
			HashMap<String, String> taskValidation = taskValidationList.get(i);
			if (taskValidation == null)
				continue;
			
			if (taskValidation.get("MEASURE_TIMELY").equals("1"))	// 及时完成次数
				nTimely++;
		}
		
		List<RowBase> taskRcdList = getStandardVerificationEventTaskRcdList(eventValidationMap);
		if (taskRcdList == null)
			return null;
		
		if (taskValidationList.size() < taskRcdList.size()){
			isEvnetValidation = false;
		}
		
		eventValidationMap.put("JOB_VALIDATION", isEvnetValidation ? "有效": "无效");
		eventValidationMap.put("MEASURE_STD_NUM", Integer.toString(taskRcdList.size()));
		eventValidationMap.put("MEASURE_ACT_NUM", Integer.toString(taskValidationList.size()));
		eventValidationMap.put("MEASURE_TIMELY_NUM", Integer.toString(nTimely));
		eventValidationMap.put("MEASURE_ACCURACY_NUM", Integer.toString(taskRcdList.size())); //"无"
		
		return eventValidationMap;
	}
	
	// 4.3.4.2。获取标准物质更换事件任务有效性列表
	List<HashMap<String, String>> getStandardSubstanceEventTaskValidationList(HashMap<String, String> resqMap) throws Exception {
		
		List<HashMap<String, String>> taskList = getStandardSubstanceAggregateTaskRstList(resqMap);
		
		calStandardSubstanceAggregateTaskRstList(resqMap, taskList);
		
		return taskList;
	}
	
	// 4.3.4.3。获取标准物质更换数据聚合任务列表
	public List<HashMap<String, String>> getStandardSubstanceAggregateTaskRstList(HashMap<String, String> resqMap) throws Exception {
		
		boolean isExist = false;
		int nReplace = 0;
		
		List<HashMap<String, String>> taskRstList = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> tempTask = null;
		
		List<RowBase> dataRcdList = getStandardSubstanceEventDataRcdList(resqMap);
		if (dataRcdList == null)
			return null;
		
		for (int i=0; i<dataRcdList.size(); i++){
			isExist = false;	
		   
			// 合并相同日期数据记录为任务记录
			for (int j=0; j<taskRstList.size(); j++){ 
				
				tempTask = taskRstList.get(j);
				
				if (tempTask.get("TASK_CODE").equals(dataRcdList.get(i).getSafeString("TASK_CODE").toString())){
					
					nReplace = Integer.parseInt(tempTask.get("REPLACE_NUM"));
					nReplace++;
					tempTask.put("REPLACE_NUM", Integer.toString(nReplace));
					taskRstList.set(j, tempTask); 
					isExist = true;
				}
			}
			
			// 如果存在同日期记录则不添加
			if (!isExist) {
				
				HashMap<String, String> task = new HashMap<String, String>();
				
				task.put("WWTP_ID", dataRcdList.get(i).getSafeString("WWTP_ID"));
				task.put("STATION_ID", dataRcdList.get(i).getSafeString("STATION_ID"));
				task.put("MEASURE_PERSON", dataRcdList.get(i).getSafeString("SUER_ID"));
				task.put("TASK_CODE", dataRcdList.get(i).getSafeString("TASK_CODE"));
				task.put("TASK_STATUS", dataRcdList.get(i).getSafeString("TASK_STATUS"));
				task.put("TASK_CYCLE", dataRcdList.get(i).getSafeString("TASK_CYCLE"));
				task.put("TASK_TOLERANCE", dataRcdList.get(i).getSafeString("TASK_TOLERANCE"));
				task.put("TASK_START_TIME", dataRcdList.get(i).getSafeString("TASK_START_TIME"));
				task.put("TASK_END_TIME", dataRcdList.get(i).getSafeString("TASK_END_TIME"));
				task.put("TASK_FINISH_TIME", dataRcdList.get(i).getSafeString("TASK_FINISH_TIME"));
				task.put("WWTP_NAME", dataRcdList.get(i).getSafeString("WWTP_NAME"));
				task.put("STATION_NAME", dataRcdList.get(i).getSafeString("STATION_NAME"));
				task.put("FLOW_TYPE_NAME", dataRcdList.get(i).getSafeString("FLOW_TYPE_NAME"));
				task.put("DEVICE_NAME", dataRcdList.get(i).getSafeString("DEVICE_NAME"));
				task.put("MEASURE_PERSON_NAME", dataRcdList.get(i).getSafeString("MEASURE_PERSON_NAME"));
				task.put("MEASURE_DATE", dataRcdList.get(i).getSafeString("REPLACE_TIME"));
				task.put("MEASURE_CONCLUSION_NAME", "完成");
				task.put("REPLACE_NUM", "1");
				
				taskRstList.add(task);
			}
		}
			
		return taskRstList;
	}

	// 4.3.4.4。计算标准物质更换数据聚合结果列表
	public void calStandardSubstanceAggregateTaskRstList(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		calStandardSubstanceTaskListBeforeTime(resqMap, taskList);
		
		calStandardSubstanceTaskListTimelyTime(resqMap, taskList);	
	}

	// 4.3.4.5.查询标准物质更换事件数据记录列表
	public List<RowBase> getStandardSubstanceEventDataRcdList(HashMap<String, String> resqMap) throws Exception {

		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strDEVICE_ID = resqMap.get("DEVICE_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
							
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrMEASURE_ITEM = strMEASURE_ITEM.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";		
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";			
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); 	// 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = " select t1.*, "
						+ " t2.TASK_STATUS, t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, t2.JOB_ID, "
						+ " t2.WWTP_ID, t2.STATION_ID, "
						+ " t3.name as WWTP_NAME,"
						+ " t4.name as STATION_NAME, "
						+ " t4.flow_type, "
						+ " t5.name DEVICE_ALIAS_NAME, "
						+ " t6.c_userealname as MEASURE_PERSON_NAME, "
						+ " t7.DEFAULT_CYCLE as JOB_CYCLE, t7.DEFAULT_TOLERANCE as JOB_TOLERANCE "
						+ " from OPERATION_STAND_SUBSTANCE t1 "
						+ " left join OPERATION_TASK t2 on t1.TASK_CODE = t2.TASK_CODE "		
						+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t3 on t4.WWTP_ID = t3.EXP_NO "
						+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NO = t5.DEVICE_NUM "
						+ " left join safe_user t6 on t1.SUER_ID = t6.s_userid "
						+ " left join OC_PARM_EVENT t7 on ( t7.JOB_ID = t2.JOB_ID  AND t7.PARM_ID = t5.MONITOR_POLLUTANTS ) "
						+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t4.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t4.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}	
		
		if (strMEASURE_ITEM.length()>0 && arrMEASURE_ITEM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrMEASURE_ITEM.length; i++){
				if(i<arrMEASURE_ITEM.length-1)
					strSQL = strSQL + "t7.PARM_ID = '"+arrMEASURE_ITEM[i]+"' OR ";
				else
					strSQL = strSQL + "t7.PARM_ID = '"+arrMEASURE_ITEM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strDEVICE_ID!=null && strDEVICE_ID.length()>0)
		{
			strSQL = strSQL + " AND ( t1.DEVICE_NO = '"+strDEVICE_ID+"' ) ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_END_DATE!=null && strMEASURE_END_DATE.length()>0)
		{
			strSQL = strSQL + "AND t2.START_TIME <= to_date('"+strMEASURE_END_DATE+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME ASC ";
			
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.4.6.查询事件任务记录列表
	public List<RowBase> getStandardSubstanceEventTaskRcdList(HashMap<String, String> resqMap) throws Exception {
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select t1.*  from OP_TASK  t1 "										
						+ " left join BC_SITE_INFO t3 on t1.STATION_ID = t3.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t2 on t3.WWTP_ID = t2.EXP_NO "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME <= to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.4.7.计算任务上次任务测量日期
	public void calStandardSubstanceTaskListBeforeTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		String strLastTime = getStandardSubstanceLastDataRcdTime(resqMap);
		
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
				
			// 获取上次任务测量日期
			if (i==0){
				if (strLastTime == null || strLastTime.length()<1){
					String strMeasureDate = task.get("TASK_FINISH_TIME");
					strLastTime = strMeasureDate;
				}
					
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			else{
				HashMap<String, String> taskBefore = taskList.get(i-1);
				strLastTime = taskBefore.get("MEASURE_DATE");
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			
			taskList.set(i, task);
		}
	}
	
	// 4.3.4.8.计算任务应该完成日期
	public void calStandardSubstanceTaskListTimelyTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		// 遍历计算间隔日期
        for (int i=0; i<taskList.size();i++){
        	HashMap<String, String> task = taskList.get(i);
        	
        	String strTaskEndTime= task.get("TASK_END_TIME");
        	String strTaskFinishTime = task.get("TASK_FINISH_TIME");
        	String strThisTime = task.get("MEASURE_DATE");
        	String strLastTime = task.get("MEASURE_BEFORE_DATE");

        	Date dateEnd = sdf.parse(strTaskEndTime);
        	Date dateFinish = sdf.parse(strTaskFinishTime); 	
        	Date dateThis = sdf.parse(strThisTime);
        	Date dateLast = sdf.parse(strLastTime);
        	
        	int nIntervalDays = (int)((dateThis.getTime()-dateLast.getTime())/(1000*60*60*24));
			task.put("MEASURE_DATE_INTERVAL", Integer.toString(nIntervalDays));
        				        	
        	nIntervalDays = (int)((dateFinish.getTime()-dateEnd.getTime())/(1000*60*60*24));       	
			task.put("MEASURE_TIMELY", nIntervalDays < 1 ? "1" : "0");
			task.put("MEASURE_TIMELY_NAME", nIntervalDays < 1 ? "及时" : "不及时");		
        }
	}
	
	// 4.3.4.9.获取上次最近的数据记录日期
	public String getStandardSubstanceLastDataRcdTime(HashMap<String, String> resqMap) throws Exception {
		
		List<RowBase> rcdList = getStandardVerificationBeforeDataRcdList(resqMap);
		if (rcdList == null || rcdList.size()<1)
			return "";
		
		String strLastTime = rcdList.get(0).get("TASK_FINISH_TIME").toString();	
		return strLastTime;
	}
	
	// 4.3.4.10.获取指定日期之前的测量数据记录
	public List<RowBase> getStandardSubstanceBeforeDataRcdList(HashMap<String, String> resqMap) throws Exception {
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strDEVICE_ID = resqMap.get("DEVICE_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = " select * from ( "
						+ " select t1.*, "
						+ " t2.TASK_STATUS, t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, t2.JOB_ID, "
						+ " t2.WWTP_ID, t2.STATION_ID, "
						+ " t3.name as WWTP_NAME,"
						+ " t4.name as STATION_NAME, "
						+ " t4.flow_type, "
						+ " t5.name DEVICE_ALIAS_NAME, "
						+ " t6.c_userealname as MEASURE_PERSON_NAME, "
						+ "  t7.DEFAULT_CYCLE as JOB_CYCLE, t7.DEFAULT_TOLERANCE as JOB_TOLERANCE, "
						+ " from OPERATION_STAND_SUBSTANCE t1 "
						+ " left join OPERATION_TASK t2 on t1.TASK_CODE = t2.TASK_CODE "		
						+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t3 on t4.WWTP_ID = t3.EXP_NO "
						+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NO = t5.DEVICE_NUM "
						+ " left join safe_user t6 on t1.SUER_ID = t6.s_userid "
						+ " left join OC_TASK_CONFIG t7 on ( t7.JOB_ID = t2.JOB_ID  AND t7.PARM_ID = t5.MONITOR_POLLUTANTS ) "
						+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t4.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t4.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}	
		
		if (strDEVICE_ID!=null && strDEVICE_ID.length()>0)
		{
			strSQL = strSQL + " AND ( t1.DEVICE_NO = '"+strDEVICE_ID+"' ) ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + "AND t2.START_TIME < to_date('"+strMEASURE_START_DATE+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME desc "
						+ " )  where rownum = 1 ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	

	/**
	 * 获取超标比对事件有效性
	 * create by kbb 2015-11-12
	 */
	// 4.3.2.1.获取超标比对事件有效性
	public HashMap<String,String> getExceedComparisonEventValidation(HashMap<String, String> resqMap) throws Exception {
		
		boolean isEvnetValidation = true;	
		int nAccuracy = 0;
		int nTimely = 0;
		
		HashMap<String, String> eventValidationMap = cloneHashMap(resqMap);
		
		List<HashMap<String, String>> taskValidationList = getExceedComparisonEventTaskValidationList(eventValidationMap); 
		if (taskValidationList == null)
			return null;
		
		for (int i=0; i<taskValidationList.size(); i++){
			HashMap<String, String> taskValidation = taskValidationList.get(i);
			if (taskValidation == null)
				continue;
			
			if (taskValidation.get("MEASURE_ACCURACY").equals("1")) // 偏差合格次数
				nAccuracy++;
			
			if (taskValidation.get("MEASURE_TIMELY").equals("1"))	// 及时完成次数
				nTimely++;
			
			if (taskValidation.get("MEASURE_ACCURACY").equals("0"))
				isEvnetValidation = false;
			
			if (taskValidation.get("MEASURE_TIMELY").equals("0"))
				isEvnetValidation = false;
		}
		
		List<RowBase> taskRcdList = getExceedComparisonEventTaskRcdList(eventValidationMap);
		if (taskRcdList == null)
			return null;
		
		if (taskValidationList.size() < taskRcdList.size()){
			isEvnetValidation = false;
		}
		
		eventValidationMap.put("JOB_VALIDATION", isEvnetValidation ? "有效": "无效");
		eventValidationMap.put("MEASURE_STD_NUM", Integer.toString(taskRcdList.size()));
		eventValidationMap.put("MEASURE_ACT_NUM", Integer.toString(taskValidationList.size()));
		eventValidationMap.put("MEASURE_TIMELY_NUM", Integer.toString(nTimely));
		eventValidationMap.put("MEASURE_ACCURACY_NUM", Integer.toString(nAccuracy));
		
		return eventValidationMap;
	}
	
	// 4.3.2.2.获取超标比对任务有效性列表
	public List<HashMap<String, String>> getExceedComparisonEventTaskValidationList(HashMap<String, String> resqMap) throws Exception {
		
		List<HashMap<String, String>> taskList = getExceedComparisonAggregateTaskRstList(resqMap);
		
		calExceedComparisonAggregateTaskRstList(resqMap, taskList);
		
		return taskList;
	}
	
	// 4.3.2.3.获取超标比对聚合任务列表
	public List<HashMap<String, String>> getExceedComparisonAggregateTaskRstList(HashMap<String, String> resqMap) throws Exception {
		
		boolean isExist = false;
		double dMin = 0.0;
		double dMax = 0.0;
		double dDeviation = 0.0;
		
		List<HashMap<String, String>> taskRstList = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> tempTask = null;
		
		List<RowBase> dataRcdList = getExceedComparisonEventDataRcdList(resqMap);
		if (dataRcdList == null)
			return null;
		
		for (int i=0; i<dataRcdList.size(); i++){
			isExist = false;	
		   
			// 合并相同日期数据记录为任务记录
			for (int j=0; j<taskRstList.size(); j++){ 
				
				tempTask = taskRstList.get(j);
				if (tempTask.get("TASK_ID").equals(dataRcdList.get(i).getSafeString("TASK_ID").toString())){
					
					// 获取合格偏差最大最小值
					dDeviation = Double.parseDouble(dataRcdList.get(i).getSafeString("MEASURE_DEVIATION").toString());
					dMin = Double.parseDouble(tempTask.get("MEASURE_MIN"));
					dMax = Double.parseDouble(tempTask.get("MEASURE_MAX"));
					
					if (dDeviation<dMin)
						dMin = dDeviation;
						
					if (dDeviation>dMax)
						dMax = dDeviation;
						
					tempTask.put("MEASURE_MIN", Double.toString(dMin));
					tempTask.put("MEASURE_MAX", Double.toString(dMax));
					
					// 获取测量次数和合格次数
					boolean  isAccuracy = true;
					int nMEASURE_NUM = Integer.parseInt(tempTask.get("MEASURE_NUM"));
					int nMEASURE_ACCURACY_NUM = Integer.parseInt(tempTask.get("MEASURE_ACCURACY_NUM"));
					String strMEASURE_CONCLUSION = dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION").toString();
					if (strMEASURE_CONCLUSION.equals("1")){
						nMEASURE_ACCURACY_NUM++;
					}
					nMEASURE_NUM++;	
					
					if (nMEASURE_NUM < 3)
						isAccuracy = false;
					
					if ((nMEASURE_NUM-nMEASURE_ACCURACY_NUM) > 1)
						isAccuracy = false;
													
					tempTask.put("MEASURE_NUM", Integer.toString(nMEASURE_NUM));
					tempTask.put("MEASURE_ACCURACY_NUM", Integer.toString(nMEASURE_ACCURACY_NUM));
					tempTask.put("MEASURE_ACCURACY", (isAccuracy ? "1" : "0") );
					tempTask.put("MEASURE_CONCLUSION_NAME", (isAccuracy ? "合格" : "不合格"));
					
					taskRstList.set(j, tempTask); 
					
					isExist = true;
				}
			}
			
			// 如果存在同日期记录则不添加
			if (!isExist) {
				
				HashMap<String, String> task = new HashMap<String, String>();
				
				task.put("WWTP_ID", dataRcdList.get(i).getSafeString("WWTP_ID").toString());
				task.put("STATION_ID", dataRcdList.get(i).getSafeString("STATION_ID").toString());
				task.put("MEASURE_ITEM", dataRcdList.get(i).getSafeString("MEASURE_ITEM").toString());
				task.put("MEASURE_PERSON", dataRcdList.get(i).getSafeString("MEASURE_PERSON").toString());
				task.put("MEASURE_START_TIME", dataRcdList.get(i).getSafeString("MEASURE_START_TIME").toString());
				task.put("MEASURE_ACCURACY", dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION").toString());
				task.put("MEASURE_NUM", "1");
				task.put("MEASURE_ACCURACY_NUM", dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION").toString());
				task.put("TASK_ID", dataRcdList.get(i).getSafeString("TASK_ID").toString());
				task.put("TASK_CYCLE", dataRcdList.get(i).getSafeString("TASK_CYCLE").toString());
				task.put("TASK_TOLERANCE", dataRcdList.get(i).getSafeString("TASK_TOLERANCE").toString());
				task.put("TASK_START_TIME", dataRcdList.get(i).getSafeString("TASK_START_TIME").toString());
				task.put("TASK_END_TIME", dataRcdList.get(i).getSafeString("TASK_END_TIME").toString());
				task.put("TASK_FINISH_TIME", dataRcdList.get(i).getSafeString("TASK_FINISH_TIME").toString());
				task.put("WWTP_NAME", dataRcdList.get(i).getSafeString("WWTP_NAME").toString());
				task.put("STATION_NAME", dataRcdList.get(i).getSafeString("STATION_NAME").toString());
				task.put("FLOW_TYPE_NAME", dataRcdList.get(i).getSafeString("FLOW_TYPE_NAME").toString());
				task.put("MEASURE_PERSON_NAME", dataRcdList.get(i).getSafeString("MEASURE_PERSON_NAME").toString());
				task.put("MEASURE_CONCLUSION_NAME", dataRcdList.get(i).getSafeString("MEASURE_CONCLUSION_NAME").toString());
				task.put("MEASURE_ITEM_NAME", dataRcdList.get(i).getSafeString("MEASURE_ITEM_NAME").toString());
				
				task.put("MEASURE_DATE", dataRcdList.get(i).getSafeString("MEASURE_START_TIME").toString());
				task.put("MEASURE_MIN", dataRcdList.get(i).getSafeString("MEASURE_DEVIATION").toString());
				task.put("MEASURE_MAX", dataRcdList.get(i).getSafeString("MEASURE_DEVIATION").toString());
				
				taskRstList.add(task);
			}
		}
			
		return taskRstList;
	}
	
	// 4.3.2.4.计算超标比对聚合任务结果列表
	public void calExceedComparisonAggregateTaskRstList(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception{
		
		//calExceedComparisonTaskListBeforeTime(resqMap, taskList);
		
		calExceedComparisonTaskListTimelyTime(resqMap, taskList);	
	}
	
	// 4.3.2.5.查询超标比对事件数据记录列表
	public List<RowBase> getExceedComparisonEventDataRcdList(HashMap<String, String> resqMap) throws Exception {

		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrMEASURE_ITEM = strMEASURE_ITEM.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";		
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";			
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); 	// 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = " select t1.*, "
						+ " t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, t2.JOB_ID, "
						+ " t3.name as WWTP_NAME, "
						+ " t4.name as STATION_NAME, t4.flow_type, "
						+ " t5.name DEVICE_ALIAS_NAME, "
						+ " t6.c_userealname as MEASURE_PERSON_NAME, "
						+ " d1.S_DOMAINCAPTION as MEASURE_ITEM_NAME, "
						+ " d2.S_DOMAINCAPTION as FLOW_TYPE_NAME, "
						+ " d3.S_DOMAINCAPTION as MEASURE_CONCLUSION_NAME  "
						+ " from OP_EXCEED_COMP t1 "
						+ " left join OPERATION_TASK t2 on t1.TASK_ID = t2.TASK_CODE "
						+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t3 on t2.WWTP_ID = t3.EXP_NO "
						+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NUMBER = t5.device_num "
						+ " left join safe_user t6 on t1.MEASURE_PERSON = t6.s_userid "
						+ " left join OC_TASK_CONFIG t7 on ( t7.JOB_ID = t2.JOB_ID  AND t7.PARM_ID = t1.MEASURE_ITEM ) "
						+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'MONITOR_PARAM' AND d1.S_DOMAINCODE = t1.MEASURE_ITEM ) "
						+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
						+ " left join DATA_DEFULATDOMAIN d3 on ( d3.S_DOMAINNAME = 'OPERATION_COMPARISON_CONCLUSION' AND d3.S_DOMAINCODE = t1.MEASURE_CONCLUSION ) "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t4.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t4.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_ITEM.length()>0 && arrMEASURE_ITEM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrMEASURE_ITEM.length; i++){
				if(i<arrMEASURE_ITEM.length-1)
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' OR ";
				else
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}		
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_END_DATE!=null && strMEASURE_END_DATE.length()>0)
		{
			strSQL = strSQL + "AND t2.START_TIME <= to_date('"+strMEASURE_END_DATE+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME asc ";
			
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.2.6.查询超标比对事件任务记录列表
	public List<RowBase> getExceedComparisonEventTaskRcdList(HashMap<String, String> resqMap) throws Exception {
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select t1.*  from OP_TASK  t1 "					
						+ " left join BC_ENTERPRISE_ATTR t2 on t1.WWTP_ID = t2.EXP_NO "
						+ " left join BC_SITE_INFO t3 on t1.STATION_ID = t3.EXP_NO "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME <= to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	// 4.3.2.7.计算任务上次任务测量日期
	public void calExceedComparisonTaskListBeforeTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		String strLastTime = getExceedComparisonLastDataRcdTime(resqMap);
		
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
				
			// 获取上次任务测量日期
			if (i==0){
				if (strLastTime == null || strLastTime.length()<1){
					String strMeasureDate = task.get("MEASURE_DATE");
					strLastTime = strMeasureDate;
				}
					
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			else{
				HashMap<String, String> taskBefore = taskList.get(i-1);
				strLastTime = taskBefore.get("MEASURE_DATE");
				task.put("MEASURE_BEFORE_DATE", strLastTime);
			}
			
			taskList.set(i, task);
		}
	}
	
	// 4.3.2.8.计算任务应该完成日期
	public void calExceedComparisonTaskListTimelyTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
				
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		// 遍历计算间隔日期
        for (int i=0; i<taskList.size();i++){
        	HashMap<String, String> task = taskList.get(i);
        	
        	String strTaskEndTime= task.get("TASK_END_TIME");
        	String strTaskFinishTime = task.get("TASK_FINISH_TIME");

        	Date dateEnd = sdf.parse(strTaskEndTime);
        	Date dateFinish = sdf.parse(strTaskFinishTime);
        	
        	int nIntervalDays = (int)((dateEnd.getTime()-dateFinish.getTime())/(1000*60*60*24));
			task.put("MEASURE_DATE_INTERVAL", Integer.toString(nIntervalDays));
			        	
        	nIntervalDays = (int)((dateFinish.getTime()-dateEnd.getTime())/(1000*60*60*24));       	
			task.put("MEASURE_TIMELY", nIntervalDays < 1 ? "1" : "0");
			task.put("MEASURE_TIMELY_NAME", nIntervalDays < 1 ? "及时" : "不及时");		
        }
	}
	
	// 4.3.2.9.获取上次最近的数据记录日期
	public String getExceedComparisonLastDataRcdTime(HashMap<String, String> resqMap) throws Exception {
		
		List<RowBase> rcdList = getExceedComparisonBeforeDataRcdList(resqMap);
		if (rcdList == null || rcdList.size()<1)
			return "";
		String strLastTime = rcdList.get(0).get("MEASURE_START_TIME").toString();	
		return strLastTime;
	}
	
	// 4.3.2.10.获取指定日期之前的测量数据记录
	public List<RowBase> getExceedComparisonBeforeDataRcdList(HashMap<String, String> resqMap) throws Exception {

		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrMEASURE_ITEM = strMEASURE_ITEM.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select * from ( "
						+ " select t1.*, t2.START_TIME as TASK_START_TIME, t2.END_TIME as TASK_END_TIME, t2.FINISH_TIME as TASK_FINISH_TIME, t2.JOB_ID, "
						+ " t3.name as WWTP_NAME,t4.name as STATION_NAME, t4.flow_type, t5.name DEVICE_ALIAS_NAME, t6.c_userealname as MEASURE_PERSON_NAME, "
						+ " t7.TASK_CYCLE, t7.TASK_TOLERANCE, "
						+ " d1.S_DOMAINCAPTION as MEASURE_ITEM_NAME, d2.S_DOMAINCAPTION as FLOW_TYPE_NAME, d3.S_DOMAINCAPTION as MEASURE_CONCLUSION_NAME  "
						+ " from OP_SAMPLE_COMP t1 "
						+ " left join OPERATION_TASK t2 on t1.TASK_ID = t2.TASK_CODE "
						+ " left join BC_ENTERPRISE_ATTR t3 on t2.WWTP_ID = t3.EXP_NO "
						+ " left join BC_SITE_INFO t4 on t2.STATION_ID = t4.EXP_NO "
						+ " left join BC_SITE_DEVICE_RPT  t5 on t1.DEVICE_NUMBER = t5.device_num "
						+ " left join safe_user t6 on t1.MEASURE_PERSON = t6.s_userid "
						+ " left join OC_TASK_CONFIG t7 on t7.JOB_ID = t2.JOB_ID "
						+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'MONITOR_PARAM' AND d1.S_DOMAINCODE = t1.MEASURE_ITEM ) "
						+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t4.FLOW_TYPE ) "
						+ " left join DATA_DEFULATDOMAIN d3 on ( d3.S_DOMAINNAME = 'OPERATION_COMPARISON_CONCLUSION' AND d3.S_DOMAINCODE = t1.MEASURE_CONCLUSION ) "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t2.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t4.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_ITEM.length()>0 && arrMEASURE_ITEM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrMEASURE_ITEM.length; i++){
				if(i<arrMEASURE_ITEM.length-1)
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' OR ";
				else
					strSQL = strSQL + "t1.MEASURE_ITEM = '"+arrMEASURE_ITEM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}		
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.MEASURE_START_TIME < to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		strSQL = strSQL + " order by t1.MEASURE_START_TIME desc "
						+ " )  where rownum = 1 ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		return rcdList;
	}
	
	
	/**
	 * 获取日常巡检事件完成率
	 * create by kbb 2015-11-12
	 */
	@RequestMapping(value = "/queryDailyInspectionStatisticsTotal")
	public void queryDailyInspectionStatisticsTotal(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();      
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		resqMap.put("JOB_ID", RequestUnit.getString("JOB_ID"));
		
		HashMap<String, String> dailyInspection = getDailyInspectionEventValidation(resqMap);
		JSONObject jsonObj = JSONObject.fromObject(dailyInspection);
		outString(jsonObj.toString());
	}
	
	/**
	 * 获取日常巡检任务列表
	 * create by kbb 2015-11-12
	 */
	@RequestMapping(value = "/queryDailyInspectionTaskList")
	public void queryDailyInspectionTaskList(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();      
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		resqMap.put("JOB_ID", RequestUnit.getString("JOB_ID"));
		
		List<HashMap<String, String>> taskList = getDailyInspectionTaskRstList(resqMap);
		JSONArray jsonObj = JSONArray.fromObject(taskList);
		outString(jsonObj.toString());
	}
	
	// 6.2.2.1.获取日常巡检完成率
	public HashMap<String,String> getDailyInspectionEventValidation(HashMap<String, String> resqMap) throws Exception{
		
		int nComplete = 0;
		int nPass = 0;
		int nTimely = 0;
		boolean isValidation = true;
		
		HashMap<String, String> eventValidation = cloneHashMap(resqMap);
		List<HashMap<String, String>> eventList = getParamEventList(eventValidation);
		if (eventList.size() < 1)
			return null;
		
		eventValidation.put("JOB_NAME", eventList.get(0).get("JOB_NAME"));
		eventValidation.put("JOB_CYCLE", eventList.get(0).get("JOB_CYCLE"));
		eventValidation.put("JOB_TOLERANC", eventList.get(0).get("JOB_TOLERANC"));
		eventValidation.put("JOB_CYCLE_NAME", eventList.get(0).get("JOB_CYCLE_NAME"));
		eventValidation.put("JOB_TOLERANC_NAME", eventList.get(0).get("JOB_TOLERANC_NAME"));
		
		List<HashMap<String, String>> taskList = getDailyInspectionTaskRstList(eventValidation);
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
			
			if (task.get("TASK_STATUS").equals("1")){
				nComplete++;
			}
			
			if (task.get("TASK_TIMELY").equals("1")){
				nTimely++;
			}				
			
			if (task.get("IS_PASS").equals("1")){
				nPass++;
			}	
		}
		
		if (nComplete<taskList.size() || nTimely<taskList.size() || nPass<(0.75*taskList.size())){
			isValidation = false;
		}
		
		eventValidation.put("JOB_VALIDATION", isValidation ? "1" : "0");
		eventValidation.put("JOB_VALIDATION_DESC", isValidation ? "有效" : "无效");
		eventValidation.put("TASK_STD_NUM", Integer.toString(taskList.size()));
		eventValidation.put("TASK_ACT_NUM", Integer.toString(nComplete));
		eventValidation.put("TASK_ACT_RATE", Double.toString(nComplete/taskList.size()));
		eventValidation.put("TASK_TIMELY_NUM", Integer.toString(nTimely));
		eventValidation.put("TASK_TIMELY_RATE", Integer.toString(nTimely/taskList.size()));
		eventValidation.put("TASK_PASS_NUM", Integer.toString(nPass));
		eventValidation.put("TASK_PASS_NUM_RATE", Integer.toString(nPass/taskList.size()));
		
		return eventValidation;
	}
	
	// 6.2.2.2.获取日常巡检任务结果列表
	public List<HashMap<String, String>> getDailyInspectionTaskRstList(HashMap<String, String> resqMap) throws Exception {
		
		List<HashMap<String, String>> taskList = getDailyInspectionTaskList(resqMap);
		
		calDailyInspectionTaskLastTime(resqMap, taskList);
		
		calDailyInspectionTaskTimely(resqMap, taskList);
		
		return taskList;
	}
	
	// 6.2.2.3.获取日常巡检任务列表
	public List<HashMap<String, String>> getDailyInspectionTaskList(HashMap<String, String> resqMap) throws Exception {
				
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");

		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
        String strSQL = " select t1.*, "
				+ "  t2.TASK_STATUS, t2.START_TIME, t2.END_TIME, t2.FINISH_TIME, t2.FINISH_BY, t2.STATION_ID,"
				+ "  t3.NAME as STATION_NAME, t3.WWTP_ID, "					
				+ "  t4.NAME as WWTP_NAME, "
				+ "  t5.NAME as JOB_NAME, t5.DEFAULT_CYCLE as JOB_CYCLE, t5.DEFAULT_TOLERANCE as JOB_TOLERANCE, t5.PARM_ID as PARAM_ID "
				+ " from OP_INSP_RECORD t1 "
				+ "  left join OPERATION_TASK t2 on t2.TASK_CODE = t1.TASK_CODE "
				+ " left join BC_SITE_INFO t3 on t3.EXP_NO = t2.STATION_ID "
				+ " left join BC_ENTERPRISE_ATTR t4 on t4.EXP_NO = t3.WWTP_ID"
				+ " left join OC_PARM_EVENT t5 on t5.JOB_ID = t2.JOB_ID "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME <= to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t2.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME ASC ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable pTable = tableFactory.openTable("TASKQUERYDIC");
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param, pTable);
		
		int nItem = 0;
		int nPass = 0;
		
		List<HashMap<String, String>> taskList = new ArrayList<HashMap<String, String>>();
		for (int i=0; i<rcdList.size(); i++){

			nItem = 0;
			nPass = 0;
			
			// 计算通过项数量
			RowBase row = rcdList.get(i);
			String[] cols = row.getColumns();
			String strFld = "";
			String strVal = "";
			for (int j=0; j<cols.length; j++){
				strFld = cols[j];
				if (strFld.length()>3)
					continue;
				if (row.getValue(cols[j]) == null)
					continue;
				nItem++;
				strVal = row.getValue(cols[j]).toString();
				if (strVal.equals("1")){
					nPass++;
				}
			}
			
			HashMap<String, String> task = new HashMap<String, String>();
			task.put("WWTP_ID", rcdList.get(i).getSafeString("WWTP_ID"));
			task.put("STATION_ID", rcdList.get(i).getSafeString("STATION_ID"));
			task.put("FLOW_TYPE", rcdList.get(i).getSafeString("FLOW_TYPE"));
			task.put("JOB_ID", rcdList.get(i).getSafeString("JOB_ID"));
			task.put("TASK_CODE", rcdList.get(i).getSafeString("TASK_CODE"));
			task.put("TASK_STATUS", rcdList.get(i).getSafeString("TASK_STATUS"));
			task.put("TASK_STATUS_DESC", rcdList.get(i).getSafeString("TASK_STATUS_DESC"));
			task.put("START_TIME", rcdList.get(i).getSafeString("START_TIME"));
			task.put("END_TIME", rcdList.get(i).getSafeString("END_TIME"));
			task.put("FINISH_TIME", rcdList.get(i).getSafeString("FINISH_TIME"));
			task.put("FINISH_BY", rcdList.get(i).getSafeString("FINISH_BY"));
			task.put("IS_PASS", nPass < nItem ? "0" : "1");
			task.put("IS_PASS_DESC", nPass < nItem ? "异常" : "正常");
			taskList.add(task);
		}
		
		return taskList;
	}
	
	// 6.2.2.4.计算日常巡检上次任务时间
	public void calDailyInspectionTaskLastTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {

		String strLastTime = getDailyInspectionLastTaskTime(resqMap);
		
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
				
			// 获取上次任务测量日期
			if (i==0){
				if (strLastTime == null || strLastTime.length()<1){
					strLastTime = task.get("FINISH_TIME");
				}
				
				task.put("TASK_BEFORE_DATE", strLastTime);
			}
			else{
				HashMap<String, String> taskBefore = taskList.get(i-1);
				strLastTime = taskBefore.get("FINISH_TIME");
				task.put("TASK_BEFORE_DATE", strLastTime);
			}
			
			taskList.set(i, task);
		}
	}

	// 6.2.2.5.计算日常巡检任务及时性
	public void calDailyInspectionTaskTimely(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		Date now = new Date(); 
		DateFormat d1 = DateFormat.getDateInstance(); 
		String strNow = d1.format(now);					// 当前日期
		
		// 遍历计算间隔日期
        for (int i=0; i<taskList.size();i++){
        	HashMap<String, String> task = taskList.get(i);
        	String strDateLast = task.get("TASK_BEFORE_DATE");
        	String strDateThis = task.get("FINISH_TIME");
        	
        	Date dateLast = sdf.parse(strDateLast);
        	Date dateThis = sdf.parse(strDateThis);
        	
        	int nIntervalDays = (int)((dateThis.getTime()-dateLast.getTime())/(1000*60*60*24));
			task.put("TASK_DATE_INTERVAL", Integer.toString(nIntervalDays));
			
			Date dateTaskEnd = sdf.parse(task.get("END_TIME"));
			Date dateTaskFinish = task.get("FINISH_TIME").length() < 1 ? sdf.parse(strNow) : sdf.parse(task.get("FINISH_TIME"));
					
			nIntervalDays = (int)((dateTaskFinish.getTime() - dateTaskEnd.getTime())/(1000*60*60*24));
			task.put("TASK_TIMELY", nIntervalDays < 1 ? "1" : "0");
			task.put("TASK_TIMELY_DESC", nIntervalDays < 1 ? "及时" : "不及时");			
        }
	}
	
	// 6.2.2.6.获取水日常巡检最近上次任务日期
	public String getDailyInspectionLastTaskTime(HashMap<String, String> resqMap) throws Exception{
		
		List<RowBase> rcdList = getDailyInspectionBeforeTaskList(resqMap);
		if (rcdList == null || rcdList.size()<1)
			return "";
		
		String strLastTime = rcdList.get(0).get("FINISH_TIME") == null ? "" : rcdList.get(0).get("FINISH_TIME").toString();	
		return strLastTime;
	}
	
	// 6.2.2.7.获取以前的日常巡检任务
	public List<RowBase> getDailyInspectionBeforeTaskList(HashMap<String, String> resqMap) throws Exception{
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select * from ("
						+ "select t1.*  from OP_TASK  t1 "											
						+ " left join BC_SITE_INFO t3 on t1.STATION_ID = t3.EXP_NO "
						+ " left join BC_ENTERPRISE_ATTR t2 on t1.WWTP_ID = t2.EXP_NO "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME < to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		strSQL = strSQL + " order by t1.FINISH_TIME desc "
				+ " )  where rownum = 1 ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		
		return rcdList;
	}
	
	// 6.2.2.8.获取事件周期和容限
	public void getEventCycleAndTolerance(HashMap<String, String> resqMap){
		
		String strJOB_ID = resqMap.get("JOB_ID");
			
		String strSQL = "select t1.*  from OC_PARM_EVENT t1 where 1=1 ";
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		
		resqMap.put("JOB_CYCLE", rcdList.get(0).getValue("DEFAULT_CYCLE").toString());
		resqMap.put("JOB_TOLERANCE", rcdList.get(0).getValue("DEFAULT_TOLERANCE").toString());
		resqMap.put("JOB_NAME", rcdList.get(0).getValue("NAME").toString());
	}
	
	
	/**
	 * 获取定期维护事件完成率
	 * create by kbb 2015-11-12
	 */
	// 获取定期维护事件有效性
	@RequestMapping(value = "/queryPeriodicalMaintainanceStatisticsTotal")
	public void queryPeriodicalMaintainanceStatisticsTotal(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();      
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		resqMap.put("JOB_ID", RequestUnit.getString("JOB_ID"));
		
		HashMap<String, String> periodicalMaintainance = getPeriodicalMaintainanceEventValidation(resqMap);
		JSONObject jsonObj = JSONObject.fromObject(periodicalMaintainance);
		outString(jsonObj.toString());
	}
	
	/**
	 * 获取定期维护任务列表
	 * create by kbb 2015-11-12
	 */
	// 获取定期维护任务列表
	@RequestMapping(value = "/queryPeriodicalMaintainanceTaskList")
	public void queryPeriodicalMaintainanceTaskList(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();      
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		resqMap.put("JOB_ID", RequestUnit.getString("JOB_ID"));
		
		List<HashMap<String, String>> taskList = getPeriodicalMaintainanceTaskRstList(resqMap);
		JSONArray jsonObj = JSONArray.fromObject(taskList);
		outString(jsonObj.toString());
	}
	
	// 6.3.2.1.获取定期维护完成率
	public HashMap<String,String> getPeriodicalMaintainanceEventValidation(HashMap<String, String> resqMap) throws Exception{
		int nComplete = 0;
		int nTimely = 0;
		int nPass = 0;
		boolean isValidation = true;
		
		HashMap<String, String> eventValidation = cloneHashMap(resqMap);
		List<HashMap<String, String>> eventList = getParamEventList(eventValidation);
		if (eventList.size() < 1)
			return null;
		
		eventValidation.put("JOB_NAME", eventList.get(0).get("JOB_NAME"));
		eventValidation.put("JOB_CYCLE", eventList.get(0).get("JOB_CYCLE"));
		eventValidation.put("JOB_TOLERANC", eventList.get(0).get("JOB_TOLERANC"));
		eventValidation.put("JOB_CYCLE_NAME", eventList.get(0).get("JOB_CYCLE_NAME"));
		eventValidation.put("JOB_TOLERANC_NAME", eventList.get(0).get("JOB_TOLERANC_NAME"));
		
		List<HashMap<String, String>> taskList = getPeriodicalMaintainanceTaskRstList(eventValidation);
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
			
			if (task.get("TASK_STATUS").equals("1")){
				nComplete++;
			}
			
			if (task.get("TASK_TIMELY").equals("1")){
				nTimely++;
			}				
			
			if (task.get("IS_PASS").equals("1")){
				nPass++;
			}		
		}
		
		if (nComplete<taskList.size() || nTimely<taskList.size() || nPass<(0.75*taskList.size())){
			isValidation = false;
		}
			
		eventValidation.put("JOB_VALIDATION", isValidation ? "1" : "0");
		eventValidation.put("JOB_VALIDATION_DESC", isValidation ? "有效" : "无效");
		eventValidation.put("TASK_STD_NUM", Integer.toString(taskList.size()));
		eventValidation.put("TASK_ACT_NUM", Integer.toString(nComplete));
		eventValidation.put("TASK_ACT_RATE", Double.toString(nComplete/taskList.size()));
		eventValidation.put("TASK_TIMELY_NUM", Integer.toString(nTimely));
		eventValidation.put("TASK_TIMELY_RATE", Integer.toString(nTimely/taskList.size()));
		eventValidation.put("TASK_PASS_NUM", Integer.toString(nPass));
		eventValidation.put("TASK_PASS_NUM_RATE", Integer.toString(nPass/taskList.size()));
		
		return eventValidation;
	}
	
	// 6.3.2.2.获取定期维护任务列表
	public List<HashMap<String, String>> getPeriodicalMaintainanceTaskRstList(HashMap<String, String> resqMap) throws Exception{

		List<HashMap<String, String>> taskList = getPeriodicalMaintainanceTaskList(resqMap);
		
		calPeriodicalMaintainanceTaskLastTime(resqMap, taskList);
		
		calPeriodicalMaintainanceTaskTimely(resqMap, taskList);
		return taskList;
	}
	
	// 6.3.2.3.获取定期维护任务列表
	public List<HashMap<String, String>> getPeriodicalMaintainanceTaskList(HashMap<String, String> resqMap) throws Exception {				
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");

		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
        String strSQL = " select t1.*, "
				+ "  t2.TASK_STATUS, t2.START_TIME, t2.END_TIME, t2.FINISH_TIME, t2.FINISH_BY, t2.STATION_ID,"
				+ "  t3.NAME as STATION_NAME, t3.WWTP_ID, "					
				+ "  t4.NAME as WWTP_NAME, "
				+ "  t5.NAME as JOB_NAME, t5.DEFAULT_CYCLE as JOB_CYCLE, t5.DEFAULT_TOLERANCE as JOB_TOLERANCE, t5.PARM_ID as PARAM_ID "
				+ " from OP_MAIN_RECORD t1 "
				+ "  left join OPERATION_TASK t2 on t2.TASK_CODE = t1.TASK_CODE "
				+ " left join BC_SITE_INFO t3 on t3.EXP_NO = t2.STATION_ID "
				+ " left join BC_ENTERPRISE_ATTR t4 on t4.EXP_NO = t3.WWTP_ID"
				+ " left join OC_PARM_EVENT t5 on t5.JOB_ID = t2.JOB_ID "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME <= to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t2.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME ASC ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable pTable = tableFactory.openTable("TASKQUERYDIC");
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param, pTable);
		
		int nItem = 0;
		int nPass = 0;
		
		List<HashMap<String, String>> taskList = new ArrayList<HashMap<String, String>>();
		for (int i=0; i<rcdList.size(); i++){

			nItem = 0;
			nPass = 0;
			
			// 计算通过项数量
			RowBase row = rcdList.get(i);
			String[] cols = row.getColumns();
			String strFld = "";
			String strVal = "";
			for (int j=0; j<cols.length; j++){
				strFld = cols[j];
				if (strFld.length()>3)
					continue;
				if (row.getValue(cols[j]) == null)
					continue;
				nItem++;
				strVal = row.getValue(cols[j]).toString();
				if (strVal.equals("1")){
					nPass++;
				}
			}
			
			HashMap<String, String> task = new HashMap<String, String>();
			task.put("WWTP_ID", rcdList.get(i).getSafeString("WWTP_ID"));
			task.put("STATION_ID", rcdList.get(i).getSafeString("STATION_ID"));
			task.put("FLOW_TYPE", rcdList.get(i).getSafeString("FLOW_TYPE"));
			task.put("JOB_ID", rcdList.get(i).getSafeString("JOB_ID"));
			task.put("TASK_CODE", rcdList.get(i).getSafeString("TASK_CODE"));
			task.put("TASK_STATUS", rcdList.get(i).getSafeString("TASK_STATUS"));
			task.put("TASK_STATUS_DESC", rcdList.get(i).getSafeString("TASK_STATUS_DESC"));
			task.put("START_TIME", rcdList.get(i).getSafeString("START_TIME"));
			task.put("END_TIME", rcdList.get(i).getSafeString("END_TIME"));
			task.put("FINISH_TIME", rcdList.get(i).getSafeString("FINISH_TIME"));
			task.put("FINISH_BY", rcdList.get(i).getSafeString("FINISH_BY"));
			task.put("IS_PASS", nPass < nItem ? "0" : "1");
			task.put("IS_PASS_DESC", nPass < nItem ? "异常" : "正常");
			taskList.add(task);
		}
		
		return taskList;
	}
	
	// 6.3.2.4.获取定期维护上次任务时间
	public void calPeriodicalMaintainanceTaskLastTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception{
		
		String strLastTime = getPeriodicalMaintainanceLastTaskTime(resqMap);
		
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
				
			// 获取上次任务测量日期
			if (i==0){
				if (strLastTime == null || strLastTime.length()<1){
					String strMeasureDate = task.get("FINISH_TIME");
					strLastTime = strMeasureDate;
				}
					
				task.put("TASK_BEFORE_DATE", strLastTime);
			}
			else{
				HashMap<String, String> taskBefore = taskList.get(i-1);
				strLastTime = taskBefore.get("FINISH_TIME");
				task.put("TASK_BEFORE_DATE", strLastTime);
			}
			
			taskList.set(i, task);
		}
	} 
	
	// 6.3.2.5.计算定期维护任务及时性
	public void calPeriodicalMaintainanceTaskTimely(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
		
		boolean bTimely = true;
		
		// 遍历计算间隔日期
        for (int i=0; i<taskList.size();i++){
        	HashMap<String, String> task = taskList.get(i);
		
        	//String strTaskStatus = task.get("TASK_STATUS"); 
        	
			task.put("TASK_TIMELY", bTimely ? "1" : "0");
			task.put("TASK_TIMELY_DESC", bTimely ? "及时" : "不及时");
			taskList.set(i, task);
        }
	}
	
	// 6.3.2.6.获取定期维护最近上次任务日期
	public String getPeriodicalMaintainanceLastTaskTime(HashMap<String, String> resqMap) throws Exception{
		
		List<RowBase> rcdList = getDailyInspectionBeforeTaskList(resqMap);
		if (rcdList == null || rcdList.size()<1)
			return "";
		
		String strLastTime = rcdList.get(0).getSafeString("FINISH_TIME");	
		return strLastTime;
	}
	
	// 6.3.2.7.获取以前的定期维护任务
	public List<RowBase> getPeriodicalMaintainanceBeforeTaskList(HashMap<String, String> resqMap) throws Exception{
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
        String strSQL = " select * from ("
        		+ " select t1.*, "
				+ "  t2.TASK_STATUS,t2.STATION_ID, "
				+ "  t3.NAME as STATION_NAME, t3.WWTP_ID, "					
				+ "  t4.NAME as WWTP_NAME, "
				+ "  t5.NAME as JOB_NAME, t5.DEFAULT_CYCLE as JOB_CYCLE, t5.DEFAULT_TOLERANCE as JOB_TOLERANCE, t5.PARM_ID as PARAM_ID "
				+ " from OP_MAIN_RECORD t1 "
				+ "  left join OPERATION_TASK t2 on t2.TASK_CODE = t1.TASK_CODE "
				+ "  left join BC_SITE_INFO t3 on t3.EXP_NO = t2.STATION_ID "
				+ "  left join BC_ENTERPRISE_ATTR t4 on t4.EXP_NO = t3.WWTP_ID"
				+ "  left join OC_PARM_EVENT t5 on t5.JOB_ID = t2.JOB_ID "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t2.START_TIME < to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t2.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		strSQL = strSQL + " order by t2.START_TIME desc "
				+ " )  where rownum = 1 ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		
		return rcdList;
	}
		

	/**
	 * 获取故障维修事件完成率
	 * create by kbb 2015-11-12
	 */
	// 获取故障维修事件有效性
	@RequestMapping(value = "/queryFailureRepairStatisticsTotal")
	public void queryFailureRepairStatisticsTotal(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();      
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		resqMap.put("JOB_ID", RequestUnit.getString("JOB_ID"));
		
		HashMap<String, String> FailureRepair = getFailureRepairEventValidation(resqMap);
		JSONObject jsonObj = JSONObject.fromObject(FailureRepair);
		outString(jsonObj.toString());
	}
	
	/**
	 * 获取故障维修任务列表
	 * create by kbb 2015-11-12
	 */
	// 获取故障维修任务列表
	@RequestMapping(value = "/queryFailureRepairTaskList")
	public void queryFailureRepairTaskList(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();      
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		resqMap.put("JOB_ID", RequestUnit.getString("JOB_ID"));
		
		List<HashMap<String, String>> taskList = getFailureRepairTaskRstList(resqMap);
		JSONArray jsonObj = JSONArray.fromObject(taskList);
		outString(jsonObj.toString());
	}
	
	// 6.4.2.1.获取故障维修完成率
	public HashMap<String,String> getFailureRepairEventValidation(HashMap<String, String> resqMap) throws Exception{
		int nComplete = 0;
		int nTimely = 0;
		boolean isValidation = true;
		
		HashMap<String, String> eventValidation = cloneHashMap(resqMap);
		List<HashMap<String, String>> taskList = getFailureRepairTaskRstList(resqMap);
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
			
			if (task.get("TASK_STATUS").equals("1")){
				nComplete++;
			}
			
			if (task.get("TASK_TIMELY").equals("1")){
				nTimely++;
			}					
		}
		
		if (nComplete<taskList.size() || nTimely<taskList.size() /*|| nPass<(0.75*taskList.size())*/){
			isValidation = false;
		}
			
		eventValidation.put("JOB_VALIDATION", isValidation ? "1" : "0");
		eventValidation.put("JOB_VALIDATION_DESC", isValidation ? "有效" : "无效");
		eventValidation.put("TASK_STD_NUM", Integer.toString(taskList.size()));
		eventValidation.put("TASK_ACT_NUM", Integer.toString(nComplete));
		eventValidation.put("TASK_ACT_RATE", Double.toString(nComplete/taskList.size()));
		eventValidation.put("TASK_TIMELY_NUM", Integer.toString(nTimely));
		eventValidation.put("TASK_TIMELY_RATE", Integer.toString(nTimely/taskList.size()));
		eventValidation.put("TASK_PASS_NUM", "无"/*Integer.toString(nPass)*/);
		eventValidation.put("TASK_PASS_NUM_RATE", "无"/*Integer.toString(nPass/taskList.size())*/);
		
		return eventValidation;
	}
	
	// 6.4.2.2.获取故障维修任务列表
	public List<HashMap<String, String>> getFailureRepairTaskRstList(HashMap<String, String> resqMap) throws Exception{

		List<HashMap<String, String>> taskList = getFailureRepairTaskList(resqMap);
		
		calFailureRepairTaskLastTime(resqMap, taskList);
		
		calFailureRepairTaskTimely(resqMap, taskList);
		
		return taskList;
	}
	
	// 6.4.2.3.获取故障维修任务列表
	public List<HashMap<String, String>> getFailureRepairTaskList(HashMap<String, String> resqMap) throws Exception {
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");

		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
        String strSQL = " select t1.WWTP_ID, t1.STATION_ID, t1.FLOW_TYPE, t1.JOB_ID, t1.IS_UNUSUAL, "
				+ " t1.OPERATION_GROUP_ID, t1.TASK_STATUS, t1.START_TIME, t1.END_TIME, t1.FINISH_TIME, t1.FINISH_BY, "					
				+ " t4.* "
				+ " from OP_TASK  t1 "
				+ " left join BC_ENTERPRISE_ATTR t2 on t1.WWTP_ID = t2.EXP_NO "
				+ " left join BC_SITE_INFO t3 on t1.STATION_ID = t3.EXP_NO "
				+ " left join OP_FAILURE_REPAIR t4 on t1.TASK_CODE = t4.TASK_ID "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t1.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME <= to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		strSQL = strSQL + " order by t1.START_TIME ASC ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		
		//int nPass = 0;
		
		List<HashMap<String, String>> taskList = new ArrayList<HashMap<String, String>>();
		for (int i=0; i<rcdList.size(); i++){

			//nPass = 0;
			
			/*
			// 计算通过项数量
			RowBase row = rcdList.get(i);
			String[] cols = row.getColumns();
			for (int j=0; j<cols.length; j++){
				String strFld = cols[j];
				String strVal = row.getValue(cols[j]).toString();
				if (strVal.equals("1")){
					nPass++;
				}
			}
			*/
			
			HashMap<String, String> task = new HashMap<String, String>();
			task.put("WWTP_ID", rcdList.get(i).getSafeString("WWTP_ID").toString());
			task.put("STATION_ID", rcdList.get(i).getSafeString("STATION_ID").toString());
			task.put("FLOW_TYPE", rcdList.get(i).getSafeString("FLOW_TYPE").toString());
			task.put("JOB_ID", rcdList.get(i).getSafeString("JOB_ID").toString());
			task.put("TASK_CODE", rcdList.get(i).getSafeString("TASK_ID").toString());
			//task.put("IS_UNUSUAL", rcdList.get(i).getSafeString("IS_UNUSUAL").toString());
			task.put("OPERATION_GROUP_ID", rcdList.get(i).getSafeString("OPERATION_GROUP_ID").toString());
			task.put("TASK_STATUS", rcdList.get(i).getSafeString("TASK_STATUS").toString());
			task.put("START_TIME", rcdList.get(i).getSafeString("START_TIME").toString());
			task.put("END_TIME", rcdList.get(i).getSafeString("END_TIME").toString());
			task.put("FINISH_TIME", rcdList.get(i).getSafeString("FINISH_TIME").toString());
			task.put("FINISH_BY", rcdList.get(i).getSafeString("FINISH_BY").toString());
			//task.put("IS_PASS", nPass < cols.length ? "0" : "1");
			//task.put("IS_PASS_DESC", nPass < cols.length ? "正常" : "异常");
			taskList.add(task);
		}
		
		return taskList;
	}
	
	// 6.4.2.4.获取故障维修上次任务时间
	public void calFailureRepairTaskLastTime(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception{
		
		String strLastTime = getDailyInspectionLastTaskTime(resqMap);
		
		for (int i=0; i<taskList.size(); i++){
			HashMap<String, String> task = taskList.get(i);
				
			// 获取上次任务测量日期
			if (i==0){
				if (strLastTime == null || strLastTime.length()<1){
					String strMeasureDate = task.get("START_TIME");
					strLastTime = strMeasureDate;
				}
					
				task.put("TASK_BEFORE_DATE", strLastTime);
			}
			else{
				HashMap<String, String> taskBefore = taskList.get(i-1);
				strLastTime = taskBefore.get("FINISH_TIME");
				task.put("TASK_BEFORE_DATE", strLastTime);
			}
			
			taskList.set(i, task);
		}
	} 
	
	// 6.4.2.5.计算故障维修任务及时性
	public void calFailureRepairTaskTimely(HashMap<String, String> resqMap, List<HashMap<String, String>> taskList) throws Exception {
				
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		
		// 遍历计算间隔日期
        for (int i=0; i<taskList.size();i++){
        	HashMap<String, String> task = taskList.get(i);
        	String strDateThis = task.get("START_TIME");
        	
        	Date dateLast = cal.getTime();
        	Date dateThis = sdf.parse(strDateThis);
        	
        	int nIntervalDays = (int)((dateThis.getTime()-dateLast.getTime())/(1000*60*60*24));
			task.put("TASK_DATE_INTERVAL", Integer.toString(nIntervalDays));
			
			Date dateTaskEnd = sdf.parse(task.get("END_TIME"));
			Date dateTaskFinish = sdf.parse(task.get("FINISH"));
			
			nIntervalDays = (int)((dateTaskFinish.getTime() - dateTaskEnd.getTime())/(1000*60*60*24));
			task.put("TASK_TIMELY", nIntervalDays < 1 ? "1" : "0");
			task.put("TASK_TIMELY_DESC", nIntervalDays < 1 ? "及时" : "不及时");	
        }
	}
	
	// 6.4.2.6.获取故障维修最近上次任务日期
	public String getFailureRepairLastTaskTime(HashMap<String, String> resqMap) throws Exception{
		
		List<RowBase> rcdList = getDailyInspectionBeforeTaskList(resqMap);
		if (rcdList == null || rcdList.size()<1)
			return "";
		String strLastTime = rcdList.get(0).getSafeString("FINISH_TIME");	
		return strLastTime;
	}
	
	// 6.4.2.7.获取以前的故障维修任务
	public List<RowBase> getFailureRepairBeforeTaskList(HashMap<String, String> resqMap) throws Exception{
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strMEASURE_YEAR = resqMap.get("MEASURE_YEAR");
		String strMEASURE_START_MONTH = resqMap.get("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = resqMap.get("MEASURE_END_MONTH");
		String strJOB_ID = resqMap.get("JOB_ID");
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
						
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_DATE = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_DATE);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
			
		String strSQL = "select * from ("
						+ "select t1.*  from OP_TASK  t1 "					
						+ " left join BC_ENTERPRISE_ATTR t2 on t1.WWTP_ID = t2.EXP_NO "
						+ " left join BC_SITE_INFO t3 on t1.STATION_ID = t3.EXP_NO "
						+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t1.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.START_TIME < to_date('"+strMEASURE_END_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strJOB_ID!=null && strJOB_ID.length()>0)
		{
			strSQL = strSQL + "  AND ( t1.JOB_ID = '"+strJOB_ID+"') ";
		}
		
		strSQL = strSQL + " order by t1.FINISH_TIME desc "
				+ " )  where rownum = 1 ";
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);
		
		return rcdList;
	}
	
	/**
	 * 获取数据传输有效率统计结果
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping(value = "/getDataTransferValidation")
	public void getDataTransferValidation(HttpServletRequest resq, HttpServletResponse res) throws Exception{
		
		// 1、获取数据传输率C=D/E
		
		// 2、获取数据有效率 P=S/M
		
		// 3、数据传输有效率  Z=C*P	
	}
	
	/**
	 * 获取实收数据个数之和 D
	 * @param resqMap
	 * @return
	 */
	public long getRealDataNum(HashMap<String, String> resqMap){
		
		// 1、
		return 0;
	}
	
	/**
	 * 获取应收数据个数之和 E
	 * @param resqMap
	 */
	public long getReceivableDataNum(HashMap<String, String> resqMap){
		
		// 1、获取各监测点数据个数之和  E=P1+P2+…+Pn
		
		// 2、获取单个监测点应收数据个数P=S×(M-N）+S×(X-Y)
		
		return 0;
	}

	/**
	 * 获取实收有效数据组数量S
	 * @param resqMap
	 * @return
	 */
	public long getRealValidatePacketNum(HashMap<String, String> resqMap){
		
		
		return 0; 
	}
	
	/**
	 * 获取应收数据组数量M
	 * @param resqMap
	 * @return
	 */
	public long getReceivableValidatePacketNum(HashMap<String, String> resqMap){
		return 0;
	}
		
	
	/**
	 * 获取数据传输率统计结果
	 * create by kbb 2015-11-11
	 */
	@RequestMapping(value = "/getDataTransferStatisticsTotal")
	public void getDataTransferStatisticsTotal(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<String, String>();
		
		// 转换年份月份为日期
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
		String strWWTP_ID = RequestUnit.getString("WWTP_ID");
		String strSTATION_ID = RequestUnit.getString("STATION_ID");
		String strFLOW_NAME = RequestUnit.getString("FLOW_NAME");
		String strMEASURE_YEAR = RequestUnit.getString("MEASURE_YEAR");
		String strMEASURE_START_MONTH = RequestUnit.getString("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = RequestUnit.getString("MEASURE_END_MONTH");
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_MONTH = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_MONTH);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
           
        String strMN = getDataCollectDevMN(strWWTP_ID, strFLOW_NAME);
        
        resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", strSTATION_ID);
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MN", strMN);
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_DATE", strMEASURE_START_DATE);
		resqMap.put("MEASURE_END_DATE", strMEASURE_END_DATE);
		
		List<HashMap<String, String>> dataTransferList = getStationParamTransferRateList(resqMap);
		JSONArray jsonObj = JSONArray.fromObject(dataTransferList);
		outString(jsonObj.toString());
	}
	
	// 5.2.3.1.获取站点数据上传率列表
	public List<HashMap<String, String>> getStationParamTransferRateList(HashMap<String, String> resqMap) throws Exception {
		
		List<HashMap<String, String>> dataTransferList= new ArrayList<HashMap<String, String>>();		
		List<HashMap<String, String>> paramList = getStationParamList(resqMap);
		for (int i=0; i<paramList.size(); i++){
			resqMap.put("PARAM_ID", paramList.get(i).get("PARAM_ID"));
			resqMap.put("PARAM_NAME", paramList.get(i).get("PARAM_NAME"));
			dataTransferList.add(getParamTransferRate(resqMap));
		}
		return dataTransferList;
	}
	
	// 5.2.3.2.获取站点数据参数项列表
	public List<HashMap<String, String>> getStationParamList(HashMap<String, String> resqMap){
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		String strSQL = " select t1.*,  "
				+ " d1.S_DOMAINCAPTION as POLLUTANTS_NAME, d2.S_DOMAINCAPTION as FLOW_TYPE_NAME "
				+ " from BC_SITE_POLL t1 "
				+ " left join BC_ENTERPRISE_ATTR t2 on t1.WSCLC_ID = t2.EXP_NO  "
				+ " left join BC_SITE_INFO t3 on t1.SITE_ID = t3.EXP_NO "
				+ " left join DATA_DEFULATDOMAIN d1 on ( d1.S_DOMAINNAME = 'MONITOR_PARAM' AND d1.S_DOMAINCODE = t1.NAME ) "
				+ " left join DATA_DEFULATDOMAIN d2 on ( d2.S_DOMAINNAME = 'STATION_FLOW_TYPE' AND d2.S_DOMAINCODE = t3.FLOW_TYPE ) "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t1.WSCLC_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.WSCLC_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.SITE_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.SITE_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		List<GlobalParameter> parameter = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, parameter);		// 此处关联总字典表，getList函数需重载
		if (rcdList.size()<1)
			return null;
		
		List<HashMap<String, String>> paramList = new ArrayList<HashMap<String, String>>();
		for (int i=0; i<rcdList.size(); i++){
			HashMap<String, String> param = new HashMap<String, String>();
			param.put("PARAM_ID", rcdList.get(i).getSafeString("NAME").toString());
			param.put("PARAM_NAME", rcdList.get(i).getSafeString("POLLUTANTS_NAME").toString());
			paramList.add(param);
		}
		if (paramList.size()<1)
			return null;
		
		return paramList;
	}
	
	// 5.2.3.3.获取数据项上传率
	public HashMap<String,String> getParamTransferRate(HashMap<String, String> resqMap) throws Exception{
		
		HashMap<String,String> paramTransferRate = cloneHashMap(resqMap);
			
		long nAcquisitionOffLineTime = getAcquisitionOffLineTime(resqMap);	//数采仪掉线时间

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date dateStartTime = sdf.parse(resqMap.get("MEASURE_START_DATE")); 
		Date dateEndTime = sdf.parse(resqMap.get("MEASURE_END_DATE")); 
		long nStationOperateTime = (dateEndTime.getTime()-dateStartTime.getTime())/1000; //运行时间
		
		double dTransferRate = 1 - nAcquisitionOffLineTime/nStationOperateTime;
		paramTransferRate.put("TRANSFER_RATE", Double.toString(dTransferRate));
		
		return paramTransferRate;
	}
	
	// 5.2.3.4.查询数据项监测数据记录数
	public long getMonitorDataRcdNum(HashMap<String, String> resqMap){
		
		String strMN = resqMap.get("MN");
		String strMEASURE_ITEM = resqMap.get("PARAM_ID");
		String strMEASURE_START_DATE = resqMap.get("MEASURE_START_DATE");
		String strMEASURE_END_DATE = resqMap.get("MEASURE_END_DATE");
		
		String strSQL = " select count(t1.GUID) as DATA_NUM "
				+ " from MONITOR_DATA t1 "
				+ " where 1=1";
		
		if (strMN !=null && strMN.length()>0)
		{
			strSQL = strSQL + " AND ( t1.MN = '"+strMN+"' ) ";
		}
		
		if (strMEASURE_ITEM !=null && strMEASURE_ITEM.length()>0)
		{
			strSQL = strSQL + " AND ( t1.PARMNAME = '"+strMEASURE_ITEM+"' ) ";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.DATATIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_END_DATE!=null && strMEASURE_END_DATE.length()>0)
		{
			strSQL = strSQL + "AND t1.DATATIME <= to_date('"+strMEASURE_END_DATE+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);	
		if (rcdList == null || rcdList.size()<1)
			return 0;
				
		return rcdList.get(0).getSafeInt("DATA_NUM");
	}
	
	// 5.2.3.5.获取数据项应上传数据记录数
	public long getStandardDataRcdNum(HashMap<String, String> resqMap) throws Exception{
		
		//按24小时运行计算
		//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		//Date dateStartTime = sdf.parse(resqMap.get("MEASURE_START_DATE")); 
		//Date dateEndTime = sdf.parse(resqMap.get("MEASURE_END_DATE")); 
		//long nStationOperateTime = (dateEndTime.getTime()-dateStartTime.getTime())1000; 
		
		//取流量（B01）时间
		long nStationOperateTime = getStationOperateTime(resqMap);
		
		long getStandardDataRcdNum = nStationOperateTime/30; // 30s 为污染物数据上传频率
		return getStandardDataRcdNum;
	}
	
	// 5.2.3.6.计算企业(站点)运转时间
	public long getStationOperateTime(HashMap<String, String> resqMap) throws Exception{
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date dateStartTime = sdf.parse(resqMap.get("MEASURE_START_DATE")); 
		Date dateEndTime = sdf.parse(resqMap.get("MEASURE_END_DATE")); 
		long nStationOperateTime = (dateEndTime.getTime()-dateStartTime.getTime())/1000;
		return nStationOperateTime;
		
		//long nSewageFlowTime = getSewageFlowTime(resqMap);
		//long nAcquisitionOffLineTime = getAcquisitionOffLineTime(resqMap); //数采仪掉线时间
		//long nStationOperateTime = nSewageFlowTime + nAcquisitionOffLineTime;
		//return nSewageFlowTime;
	}
	
	// 5.2.3.7.计算数采仪掉线时间
	public long getAcquisitionOffLineTime(HashMap<String, String> resqMap) throws Exception{
		
		long nAcquisitionOffLineTime = 0;
		long nOffLineTime = 0;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		List<RowBase> rcdList = getAcquisitionOffLineRcdList(resqMap);
		if (rcdList == null)
			return 0;
			
		for (int i=0; i<rcdList.size(); i++){		
			nOffLineTime = 0;
			Date dateStartTime = sdf.parse(rcdList.get(i).getSafeString("OFFLINE_TIME").toString()); 
			Date dateEndTime = sdf.parse(rcdList.get(i).getSafeString("ONLINE_TIME").toString());
			nOffLineTime = dateEndTime.getTime()-dateStartTime.getTime();
			nAcquisitionOffLineTime += (nOffLineTime/1000);   
		}
		return nAcquisitionOffLineTime;
	}
	
	// 5.2.3.8.查询数采仪掉线记录
	public List<RowBase> getAcquisitionOffLineRcdList(HashMap<String, String> resqMap){
		
		String strMN = resqMap.get("MN");
		String strMEASURE_START_DATE = resqMap.get("MEASURE_START_DATE");
		String strMEASURE_END_DATE = resqMap.get("MEASURE_END_DATE");
		
		String strSQL = " select t1.*  "
				+ " from MONITOR_ABNORMAL t1 "
				+ " where 1=1";
		
		if (strMN!=null && strMN.length()>0){
			strSQL = strSQL + "AND t1.MN = '"+ strMN + "' ";
		}

		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.ONLINE_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_END_DATE!=null && strMEASURE_END_DATE.length()>0)
		{
			strSQL = strSQL + "AND t1.OFFLINE_TIME <= to_date('"+strMEASURE_END_DATE+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);		
		if (rcdList.size()<1)
			return null;
		return rcdList;
	}
	
	// 5.2.3.9.计算污水排放时间
	public long getSewageFlowTime(HashMap<String, String> resqMap){
		
		long nSewageFlowDataRcdNum = getSewageFlowDataRcdNum(resqMap);
		long nSewageFlowTime = nSewageFlowDataRcdNum*30; // 30s 为流量数据上传频率
		return nSewageFlowTime;
	}
	
	// 5.2.3.10.查询污水流量监测数据记录数
	public long getSewageFlowDataRcdNum(HashMap<String, String> resqMap){
		HashMap<String, String> tempMap = cloneHashMap(resqMap);
		tempMap.put("PARAM_ID", "B01");
		return getMonitorDataRcdNum(tempMap);
	}
	
	
	/**
	 * 获取设备运转率统计结果
	 * create by kbb 2015-11-11
	 */
	@RequestMapping(value = "/getDeviceOperationStatisticsTotal")
	public void getDeviceOperationStatisticsTotal(HttpServletRequest resq, HttpServletResponse res) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<String, String>();
		
		// 转换年份月份为日期
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
		String strMEASURE_YEAR = RequestUnit.getString("MEASURE_YEAR");
		String strMEASURE_START_MONTH = RequestUnit.getString("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = RequestUnit.getString("MEASURE_END_MONTH");
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_MONTH = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_MONTH);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
        
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_DATE", strMEASURE_START_DATE);
		resqMap.put("MEASURE_END_DATE", strMEASURE_END_DATE);
		
		List<HashMap<String, String>> deviceOperateList = getStationDeviceOperateRateList(resqMap);
		JSONArray jsonObj = JSONArray.fromObject(deviceOperateList);
		outString(jsonObj.toString());
	}
	
	// 5.3.2.1.获取站点设备运转率列表
	public List<HashMap<String, String>> getStationDeviceOperateRateList(HashMap<String, String> resqMap) throws Exception {
		
		List<HashMap<String, String>> deviceOperateRateList = new ArrayList<HashMap<String,String>>();
		List<HashMap<String, String>> deviceList = getStationDeviceList(resqMap);
		for (int i=0; i<deviceList.size(); i++){
			resqMap.put("DEVICE_NUM", deviceList.get(i).get("DEVICE_NUM"));
			resqMap.put("DEVICE_NAME", deviceList.get(i).get("DEVICE_NAME"));
			HashMap<String, String> deviceFailureRate = getDeviceFailureRate(resqMap);
			deviceOperateRateList.add(deviceFailureRate);
		}
		return deviceOperateRateList;
	}
	
	// 5.3.2.2.获取站点设备列表
	public List<HashMap<String,String>> getStationDeviceList(HashMap<String, String> resqMap){
		
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		
		String strSQL = " select t1.*  "
				+ " from BC_SITE_DEVICE_RPT t1 "
				+ " left join BC_ENTERPRISE_ATTR t2 on t1.WSCLC_ID = t2.EXP_NO  "
				+ " left join BC_SITE_INFO t3 on t1.MONITOR_POINT = t3.EXP_NO  "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t1.WSCLC_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.WSCLC_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t1.MONITOR_POINT LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t1.MONITOR_POINT LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);		// 此处关联总字典表，getList函数需重载
		if (rcdList.size()<1)
			return null;
		
		List<HashMap<String,String>> deviceList = new ArrayList<HashMap<String,String>>();
		for (int i=0; i<rcdList.size(); i++){
			HashMap<String, String> device = new HashMap<String, String>();
			device.put("DEVICE_NUM", rcdList.get(i).getSafeString("DEVICE_NUM"));
			device.put("DEVICE_NAME", rcdList.get(i).getSafeString("NAME"));
			deviceList.add(device);
		}
		if (deviceList.size()<1)
			return null;
		
		return deviceList;
	}
	
	// 5.3.2.3.计算单个设备故障率
	public HashMap<String,String> getDeviceFailureRate(HashMap<String, String> resqMap) throws Exception {
		HashMap<String, String> deviceFailureRate = cloneHashMap(resqMap);
		
		long nDeviceFailureTime = getDeviceFailureTime(resqMap); 	//故障时间
		long nDeviceFailureNum = getDeviceFailureNum(resqMap);		//故障次数
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date dateStartTime = sdf.parse(resqMap.get("MEASURE_START_DATE")); 
		Date dateEndTime = sdf.parse(resqMap.get("MEASURE_END_DATE")); 
		long nStationOperateTime = (dateEndTime.getTime()-dateStartTime.getTime())/1000;
		long nMTBF = nStationOperateTime/3600; // 平均故障间隔时间(小时)
		
		double dOperateRate = 1-nDeviceFailureTime/nStationOperateTime;
		if (nDeviceFailureNum>0)
			nMTBF = nStationOperateTime/nDeviceFailureNum;
			
		deviceFailureRate.put("OPERATE_RATE", Double.toString(dOperateRate));
		deviceFailureRate.put("DEVICE_MTBF", Long.toString(nMTBF));
		return deviceFailureRate;
	}
	
	// 5.3.2.4.计算设备故障时间
	public long getDeviceFailureTime(HashMap<String, String> resqMap) throws Exception {
		
		long nDeviceFailureTime = 0;
		long nFailureTime = 0;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		List<RowBase> rcdList = getDeviceFailureRcdList(resqMap);
		if (rcdList == null)
			return 0;
		
		for (int i=0; i<rcdList.size(); i++){
			nFailureTime = 0;
			Date dateStartTime = sdf.parse(rcdList.get(i).getSafeString("BEGIN_TIME").toString()); 
			Date dateEndTime = sdf.parse(rcdList.get(i).getSafeString("END_TIME").toString());
			nFailureTime = dateEndTime.getTime()-dateStartTime.getTime();
			nDeviceFailureTime += (nFailureTime/1000);   
		}
		
		return nDeviceFailureTime;		
	}
	
	// 5.3.2.5.计算设备故障次数
	public long getDeviceFailureNum(HashMap<String, String> resqMap){

		List<RowBase> rcdList = getDeviceFailureRcdList(resqMap);
		if (rcdList == null)
			return 0;
		
		return rcdList.size();
	}
	
	// 5.3.2.6.获取设备故障记录
	public List<RowBase> getDeviceFailureRcdList(HashMap<String, String> resqMap){
		String strWWTP_ID = resqMap.get("WWTP_ID");
		String strSTATION_ID = resqMap.get("STATION_ID");
		String strFLOW_NAME = resqMap.get("FLOW_NAME");
		String strDEVICE_NUM = resqMap.get("DEVICE_NUM");
		String strMEASURE_START_DATE = resqMap.get("MEASURE_START_DATE");
		String strMEASURE_END_DATE = resqMap.get("MEASURE_END_DATE");
		
		String[] arrWWTP_ID = strWWTP_ID.split(",");
		String[] arrSTATION_ID = strSTATION_ID.split(",");
		String[] arrFLOW_NAME = strFLOW_NAME.split(",");
		String[] arrDEVICE_NUM = strDEVICE_NUM.split(",");
		
		String strSQL = " select t1.*  "
				+ " from OP_FAILURE_REPAIR t1 "
				+ " left join OPERATION_TASK t2 on t2.TASK_CODE = t1.TASK_ID "
				+ " left join BC_SITE_INFO t3 on t3.EXP_NO = t2.STATION_ID "
				+ " left join BC_ENTERPRISE_ATTR t4 on t4.EXP_NO = t3.WWTP_ID "
				+ " left join BC_SITE_DEVICE_RPT  t5 on t5.DEVICE_NUM = t1.DEVICE_NUMBER "
				+ " where 1=1";
		
		if (strWWTP_ID.length()>0 && arrWWTP_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrWWTP_ID.length; i++){
				if(i<arrWWTP_ID.length-1)
					strSQL = strSQL + "t3.WWTP_ID LIKE '%"+arrWWTP_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t3.WWTP_ID LIKE '"+arrWWTP_ID[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strSTATION_ID.length()>0 && arrSTATION_ID.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrSTATION_ID.length; i++){
				if(i<arrSTATION_ID.length-1)
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' OR ";
				else
					strSQL = strSQL + "t2.STATION_ID LIKE '%"+arrSTATION_ID[i]+"%' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strFLOW_NAME.length()>0 && arrFLOW_NAME.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrFLOW_NAME.length; i++){
				if(i<arrFLOW_NAME.length-1)
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' OR ";
				else
					strSQL = strSQL + "t3.FLOW_TYPE = '"+arrFLOW_NAME[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strDEVICE_NUM.length()>0 && arrDEVICE_NUM.length>0){
			strSQL=strSQL + " AND ( ";
			
			for (int i=0; i<arrDEVICE_NUM.length; i++){
				if(i<arrDEVICE_NUM.length-1)
					strSQL = strSQL + "t1.DEVICE_NUMBER = '"+arrDEVICE_NUM[i]+"' OR ";
				else
					strSQL = strSQL + "t1.DEVICE_NUMBER = '"+arrDEVICE_NUM[i]+"' ";
			}
			
			strSQL=strSQL + " )";
		}
		
		if (strMEASURE_START_DATE!=null && strMEASURE_START_DATE.length()>0)
		{
			strSQL = strSQL + " AND t1.BEGIN_TIME >= to_date('"+strMEASURE_START_DATE+" 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ";
		}
		
		if (strMEASURE_END_DATE!=null && strMEASURE_END_DATE.length()>0)
		{
			strSQL = strSQL + "AND t1.BEGIN_TIME <= to_date('"+strMEASURE_END_DATE+" 23:59:59', 'yyyy-mm-dd hh24:mi:ss')  ";
		}
		
		List<GlobalParameter> param = new ArrayList<GlobalParameter>();
		List<RowBase> rcdList = DataUtil.getSelectRows(strSQL, param);		
		if (rcdList.size()<1)
			return null;
		return rcdList;
	}
	
	
	/**
	 * 自定义辅助函数
	 * create by kbb 2015-11-11
	 */
	/*
	// 转换请求条件
	public HashMap<String, String> convertHttpServletRequest1(HttpServletRequest resq) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<>();
        
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_MONTH", RequestUnit.getString("MEASURE_START_MONTH"));
		resqMap.put("MEASURE_END_MONTH", RequestUnit.getString("MEASURE_END_MONTH"));
		
		return resqMap;
	}
		
	// 转换请求条件
	public HashMap<String, String> convertHttpServletRequest2(HttpServletRequest resq) throws Exception {
		
		HashMap<String, String> resqMap = new HashMap<String, String>();
			
		// 转换年份月份为日期
		String strMEASURE_START_DATE = "";
		String strMEASURE_END_DATE = "";
		String strMEASURE_YEAR = RequestUnit.getString("MEASURE_YEAR");
		String strMEASURE_START_MONTH = RequestUnit.getString("MEASURE_START_MONTH");
		String strMEASURE_END_MONTH = RequestUnit.getString("MEASURE_END_MONTH");
		strMEASURE_START_DATE = strMEASURE_YEAR+"-"+strMEASURE_START_MONTH+"-01";
		strMEASURE_END_MONTH = strMEASURE_YEAR+"-"+strMEASURE_END_MONTH+"-01";
		
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dateEnd = sdf.parse(strMEASURE_END_MONTH);  
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateEnd);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));  // 获取月月尾日日期
        strMEASURE_END_DATE = sdf.format(cal.getTime());
        
		resqMap.put("WWTP_ID", RequestUnit.getString("WWTP_ID"));
		resqMap.put("STATION_ID", RequestUnit.getString("STATION_ID"));
		resqMap.put("FLOW_NAME", RequestUnit.getString("FLOW_NAME"));
		resqMap.put("MEASURE_YEAR", RequestUnit.getString("MEASURE_YEAR"));
		resqMap.put("MEASURE_START_DATE", strMEASURE_START_DATE);
		resqMap.put("MEASURE_END_DATE", strMEASURE_END_DATE);
		
		return resqMap;
	}
	*/
	
	// 深拷贝HashMap
	public HashMap<String, String> cloneHashMap(HashMap<String, String> resqMap){
			
		HashMap<String, String> rtnMap = new HashMap<String, String>();
		Set<Entry<String, String>> sets = resqMap.entrySet();  
        for(Entry<String, String> entry : sets) {  
        	rtnMap.put(entry.getKey(), entry.getValue());
        }
        
        return rtnMap;
	}
	
	/**
	 * 根据污水厂id和排口类型获取站点id
	 */
	protected String getStationId(String wwtpid,String stationType)
	{
		String getStationIdSql = " SELECT ms.EXP_NO FROM BC_COLLECTION_INFO dci"
				+ "	left join BC_SITE_INFO ms ON dci.SITE_ID = ms.EXP_NO"
				+ " WHERE ms.WWTP_ID = @WSCLC_ID AND FLOW_TYPE=@FLOW_TYPE AND rownum = 1";

		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		GlobalParameter wwtpIdParm = new GlobalParameter("WSCLC_ID", wwtpid);
		GlobalParameter stationTypeParm = new GlobalParameter("FLOW_TYPE", stationType);
		parms.add(wwtpIdParm);
		parms.add(stationTypeParm);
		Object stationIdObj = DataUtil.getScale(getStationIdSql, parms);
		String stationId = stationIdObj == null ?null:stationIdObj.toString();
		return stationId;
	}
	
	/**
	 * 获取数采仪设备编号
	 * gislin
	 * 2015年11月13日
	 * @param wwtpid
	 * @param stationType
	 * @return
	 */
	protected String getDataCollectDevMN(String wwtpid,String stationType){
		
		String stationId = getStationId(wwtpid, stationType);
		String getMNInfoSql = " SELECT DEVICE_NUM FROM BC_COLLECTION_INFO WHERE SITE_ID = '"+stationId+"' and rownum=1";
		Object mnObj = DataUtil.getScale(getMNInfoSql, null);
		String mn = mnObj == null ?null:mnObj.toString();
		return mn;
	}

}
